1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
3 struct X0 {
4 X0();
5 X0(int);
6 X0 f1();
7 X0 f2();
8 typedef int A;
9 typedef X0 B;
10 };
11
12 template<typename T>
13 struct X1 : X0 {
14 X1();
15 X1<T>(int);
16 (X1<T>)(float);
17 X1 f2();
18 X1 f2(int);
19 X1 f2(float);
20 X1 f2(double);
21 X1 f2(short);
22 X1 f2(long);
23 };
24
25 // Error recovery: out-of-line constructors whose names have template arguments.
X1(int)26 template<typename T> X1<T>::X1<T>(int) { } // expected-error{{out-of-line constructor for 'X1' cannot have template arguments}}
27 template<typename T> (X1<T>::X1<T>)(float) { } // expected-error{{out-of-line constructor for 'X1' cannot have template arguments}}
28
29 // Error recovery: out-of-line constructor names intended to be types
f1()30 X0::X0 X0::f1() { return X0(); } // expected-error{{qualified reference to 'X0' is a constructor name rather than a type in this context}}
31
f2()32 struct X0::X0 X0::f2() { return X0(); }
33
f2()34 template<typename T> X1<T>::X1<T> X1<T>::f2() { } // expected-warning{{missing 'typename'}}
X1(X1<T>::f2)35 template<typename T> X1<T>::X1<T> (X1<T>::f2)(int) { } // expected-warning{{missing 'typename'}}
X1(X1<T>::f2)36 template<typename T> struct X1<T>::X1<T> (X1<T>::f2)(float) { }
X1(X1<T>::f2)37 template<typename T> struct X1<T>::X1 (X1<T>::f2)(double) { }
f2(short)38 template<typename T> typename X1<T>::template X1<T> X1<T>::f2(short) { } // expected-warning {{qualified reference to 'X1' is a constructor name rather than a template name in this context}}
X1(X1<T>::f2)39 template<typename T> typename X1<T>::template X1<T> (X1<T>::f2)(long) { } // expected-warning {{qualified reference to 'X1' is a constructor name rather than a template name in this context}}
40
x1test(X1<int> x1i)41 void x1test(X1<int> x1i) {
42 x1i.f2();
43 x1i.f2(0);
44 x1i.f2(0.f);
45 x1i.f2(0.);
46 }
47
other_contexts()48 void other_contexts() {
49 X0::X0 x0; // expected-error{{qualified reference to 'X0' is a constructor name rather than a type in this context}}
50 X1<int>::X1 x1a; // expected-error{{qualified reference to 'X1' is a constructor name rather than a type in this context}}
51 X1<int>::X1<float> x1b; // expected-error{{qualified reference to 'X1' is a constructor name rather than a template name in this context}}
52
53 X0::B ok1;
54 X0::X0::A ok2;
55 X0::X0::X0 x0b; // expected-error{{qualified reference to 'X0' is a constructor name rather than a type in this context}}
56 X1<int>::X0 ok3;
57 X1<int>::X0::X0 x0c; // expected-error{{qualified reference to 'X0' is a constructor name rather than a type in this context}}
58 X1<int>::X1<float>::X0 ok4;
59
60 {
61 typename X0::X0 tn1; // expected-warning{{qualified reference to 'X0' is a constructor name rather than a type in this context}} expected-warning 0-1{{typename}}
62 typename X1<int>::X1<float> tn2; // expected-warning{{qualified reference to 'X1' is a constructor name rather than a template name in this context}} expected-warning 0-1{{typename}}
63 typename X0::B ok1; // expected-warning 0-1{{typename}}
64 typename X1<int>::X0 ok2; // expected-warning 0-1{{typename}}
65 }
66
67 {
68 struct X0::X0 tag1;
69 struct X1<int>::X1 tag2;
70 struct X1<int>::X1<int> tag3;
71 }
72
73 int a;
74 {
75 X0::X0(a); // expected-error{{qualified reference to 'X0' is a constructor name rather than a type in this context}}
76 // expected-warning@-1 {{redundant parentheses around declaration of variable named 'a'}} expected-note@-1 2{{}}
77 }
78 }
79
in_instantiation_x0()80 template<typename T> void in_instantiation_x0() {
81 typename T::X0 x0; // expected-warning{{qualified reference to 'X0' is a constructor name rather than a type in this context}}
82 typename T::A a;
83 typename T::B b;
84 }
85 template void in_instantiation_x0<X0>(); // expected-note {{instantiation of}}
86
in_instantiation_x1()87 template<typename T> void in_instantiation_x1() {
88 typename T::X1 x1; // expected-warning{{qualified reference to 'X1' is a constructor name rather than a type in this context}}
89 typename T::template X1<int> x1i; // expected-warning{{qualified reference to 'X1' is a constructor name rather than a template name in this context}}
90 typename T::X0 x0;
91 }
92 template void in_instantiation_x1<X1<int> >(); // expected-note {{instantiation of}}
93
94 namespace sfinae {
95 template<typename T> void f(typename T::X0 *) = delete; // expected-warning 0-1{{extension}}
96 template<typename T> void f(...);
g()97 void g() { f<X0>(0); }
98 }
99
100 namespace versus_injected_class_name {
101 template <typename T> struct A : T::B {
102 struct T::B *p;
103 typename T::B::type a;
Aversus_injected_class_name::A104 A() : T::B() {}
105
106 typename T::B b; // expected-warning {{qualified reference to 'B' is a constructor name rather than a type in this context}}
107 };
108 struct B {
109 typedef int type;
110 };
111 template struct A<B>; // expected-note {{in instantiation of}}
112 }
113
114 // We have a special case for lookup within using-declarations that are
115 // member-declarations: foo::bar::baz::baz always names baz's constructor
116 // in such a context, even if looking up 'baz' within foo::bar::baz would
117 // not find the injected-class-name. Likewise foo::bar::baz<T>::baz also
118 // names the constructor.
119 namespace InhCtor {
120 struct A {
121 A(int);
122 protected:
123 int T();
124 };
125 typedef A T;
126 struct B : A {
127 // This is a using-declaration for 'int A::T()' in C++98, but is an
128 // inheriting constructor declaration in C++11.
129 using InhCtor::T::T;
130 };
131 #if __cplusplus < 201103L
132 B b(123); // expected-error {{no matching constructor}}
133 // expected-note@-7 2{{candidate constructor}}
134 int n = b.T(); // ok, accessible
135 #else
136 B b(123); // ok, inheriting constructor
137 int n = b.T(); // expected-error {{'T' is a protected member of 'InhCtor::A'}}
138 // expected-note@-15 {{declared protected here}}
139
140 // FIXME: EDG and GCC reject this too, but it's not clear why it would be
141 // ill-formed.
142 template<typename T>
143 struct S : T {
144 struct U; // expected-note 6{{candidate}}
145 using T::T;
146 };
147
148 template<typename T>
149 struct S<T>::U : S {
150 using S::S;
151 };
152
153 S<A>::U ua(0); // expected-error {{no match}}
154 S<B>::U ub(0); // expected-error {{no match}}
155
156 template<typename T>
157 struct X : T {
158 using T::Z::U::U;
159 };
160 template<typename T>
161 struct X2 : T {
162 using T::Z::template V<int>::V;
163 };
164 struct Y {
165 struct Z {
166 typedef Y U;
167 template<typename T> using V = Y;
168 };
169 Y(int);
170 };
171 X<Y> xy(0);
172
173 namespace Repeat {
174 struct A {
175 struct T {
176 T(int);
177 };
178 };
179 struct Z : A {
180 using A::A::A;
181 };
182 template<typename T>
183 struct ZT : T::T {
184 using T::T::T;
185 };
186 }
187
188 namespace NS {
189 struct NS {};
190 }
191 struct DerivedFromNS : NS::NS {
192 // No special case unless the NNS names a class.
193 using InhCtor::NS::NS; // expected-error {{using declaration in class refers into 'InhCtor::NS::', which is not a class}}
194
195 };
196
197 // FIXME: Consider reusing the same diagnostic between dependent and non-dependent contexts
198 typedef int I;
199 struct UsingInt {
200 using I::I; // expected-error {{'InhCtor::I' (aka 'int') is not a class, namespace, or enumeration}}
201 };
202 template<typename T> struct UsingIntTemplate {
203 using T::T; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
204 };
205 UsingIntTemplate<int> uit; // expected-note {{here}}
206
207 // This case is odd: we don't name the constructor of a dependent base as
208 // Base::Base, but we still happen to have enough information to identify
209 // when parsing the template that we're inheriting constructors.
210 //
211 // FIXME: Once CWG 2070 is resolved, check whether this case should be
212 // accepted or not.
213 namespace DependentCtorName {
214 template <typename T> struct B { B(int); };
215 template <typename T> struct A : B<T> {
216 using X = B<T>;
217 using X::B;
218 };
219 A<int> ab = 0;
220 }
221 #endif
222 }
223