Debian Codegraph @

clang/test/SemaTemplate/elaborated-type-specifier.cpp

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2
3 namespace PR6915 {
4 template <typename T>
5 class D {
6 enum T::X v; // expected-error{{use of 'X' with tag type that does not match previous declaration}} \
7 // expected-error{{no enum named 'X' in 'PR6915::D3'}}
8 };
9
10 struct D1 {
11 enum X { value };
12 };
13 struct D2 {
14 class X { }; // expected-note{{previous use is here}}
15 };
16 struct D3 { };
17
18 template class D<D1>;
19 template class D<D2>; // expected-note{{in instantiation of}}
20 template class D<D3>; // expected-note{{in instantiation of}}
21 }
22
23 template<typename T>
24 struct DeclOrDef {
25 enum T::foo; // expected-error{{nested name specifier for a declaration cannot depend on a template parameter}}
26 // expected-error@-1{{forward declaration of enum cannot have a nested name specifier}}
27 enum T::bar { // expected-error{{nested name specifier for a declaration cannot depend on a template parameter}}
28 value
29 };
30 };
31
32 namespace PR6649 {
33 template <typename T> struct foo {
34 class T::bar; // expected-error{{nested name specifier for a declaration cannot depend on a template parameter}}
35 // expected-error@-1{{forward declaration of class cannot have a nested name specifier}}
36 class T::bar { int x; }; // expected-error{{nested name specifier for a declaration cannot depend on a template parameter}}
37 };
38 }
39
40 namespace rdar8568507 {
41 template <class T> struct A *makeA(T t);
42 }
43
44 namespace canon {
45 template <class T> void t1(struct T::X) {}
46 // expected-note@-1 {{previous definition is here}}
47 template <class T> void t1(class T::X) {}
48 // expected-error@-1 {{redefinition of 't1'}}
49
50 template <class T> void t2(struct T::template X<int>) {}
51 // expected-note@-1 {{previous definition is here}}
52 template <class T> void t2(class T::template X<int>) {}
53 // expected-error@-1 {{redefinition of 't2'}}
54
55 template <class T> constexpr int t3(typename T::X* = 0) { return 0; } // #canon-t3-0
56 template <class T> constexpr int t3(struct T::X* = 0) { return 1; } // #canon-t3-1
57 template <class T> constexpr int t3(union T::X* = 0) { return 2; } // #canon-t3-2
58 template <class T> constexpr int t3(enum T::X* = 0) { return 3; } // #canon-t3-3
59
60 struct A { using X = int; };
61 static_assert(t3<A>() == 0);
62
63 struct B { struct X {}; };
64 static_assert(t3<B>() == 1);
65 // expected-error@-1 {{call to 't3' is ambiguous}}
66 // expected-note@#canon-t3-0 {{candidate function}}
67 // expected-note@#canon-t3-1 {{candidate function}}
68
69 struct C { union X {}; };
70 static_assert(t3<C>() == 2);
71 // expected-error@-1 {{call to 't3' is ambiguous}}
72 // expected-note@#canon-t3-0 {{candidate function}}
73 // expected-note@#canon-t3-2 {{candidate function}}
74
75 struct D { enum X {}; };
76 static_assert(t3<D>() == 3);
77 // expected-error@-1 {{call to 't3' is ambiguous}}
78 // expected-note@#canon-t3-0 {{candidate function}}
79 // expected-note@#canon-t3-3 {{candidate function}}
80
81 template <class T> constexpr int t4(typename T::template X<int>* = 0) { return 0; }
82 // expected-note@-1 2{{candidate function}}
83 template <class T> constexpr int t4(struct T::template X<int>* = 0) { return 1; }
84 // expected-note@-1 2{{candidate function}}
85 template <class T> constexpr int t4(union T::template X<int>* = 0) { return 2; }
86 // expected-note@-1 2{{candidate function}}
87
88 struct E { template <class T> using X = T; };
89 static_assert(t4<E>() == 0);
90
91 struct F { template <class> struct X {}; };
92 static_assert(t4<F>() == 1); // expected-error {{call to 't4' is ambiguous}}
93
94 struct G { template <class> union X {}; };
95 static_assert(t4<G>() == 2); // expected-error {{call to 't4' is ambiguous}}
96 } // namespace canon