Debian Codegraph @

clang/test/CXX/drs/cwg11xx.cpp

raw
1 // RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++2a %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
6
7 namespace cwg1110 { // cwg1110: 3.1
8 #if __cplusplus >= 201103L
9 template <typename T>
10 T return_T();
11
12 struct A;
13
14 template <typename>
15 struct B;
16
17 decltype(return_T<A>())* a;
18 decltype(return_T<B<int>>())* b;
19 #endif
20 } // namespace cwg1110
21
22 namespace cwg1111 { // cwg1111: 3.2
23 namespace example1 {
24 template <typename> struct set; // #cwg1111-struct-set
25
26 struct X {
27 template <typename T> void set(const T &value); // #cwg1111-func-set
28 };
29 void foo() {
30 X x;
31 // FIXME: should we backport C++11 behavior?
32 x.set<double>(3.2);
33 // cxx98-error@-1 {{lookup of 'set' in member access expression is ambiguous; using member of 'X'}}
34 // cxx98-note@#cwg1111-func-set {{lookup in the object type 'X' refers here}}
35 // cxx98-note@#cwg1111-struct-set {{lookup from the current scope refers here}}
36 }
37
38 struct Y {};
39 void bar() {
40 Y y;
41 y.set<double>(3.2);
42 // expected-error@-1 {{no member named 'set' in 'cwg1111::example1::Y'}}
43 }
44 } // namespace example1
45
46 namespace example2 {
47 struct A {};
48 namespace N {
49 struct A {
50 void g() {}
51 template <class T> operator T();
52 };
53 } // namespace N
54
55 void baz() {
56 N::A a;
57 a.operator A();
58 }
59 } // namespace example2
60 } // namespace cwg1111
61
62 namespace cwg1113 { // cwg1113: partial
63 namespace named {
64 extern int a; // #cwg1113-a
65 static int a;
66 // expected-error@-1 {{static declaration of 'a' follows non-static}}
67 // expected-note@#cwg1113-a {{previous declaration is here}}
68 }
69 namespace {
70 extern int a;
71 static int a; // ok, both declarations have internal linkage
72 int b = a;
73 }
74
75 // FIXME: Per CWG1113 and CWG4, this is ill-formed due to ambiguity: the second
76 // 'f' has internal linkage, and so does not have C language linkage, so is
77 // not a redeclaration of the first 'f'.
78 //
79 // To avoid a breaking change here, Clang ignores the "internal linkage" effect
80 // of anonymous namespaces on declarations declared within an 'extern "C"'
81 // linkage-specification.
82 extern "C" void f();
83 namespace {
84 extern "C" void f();
85 }
86 void g() { f(); }
87 }
88
89 // cwg1150: na