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 f1();
5 X0 f2();
6 };
7
8 template<typename T>
9 struct X1 {
10 X1<T>(int);
11 (X1<T>)(float);
12 X1 f2();
13 X1 f2(int);
14 X1 f2(float);
15 };
16
17 // Error recovery: out-of-line constructors whose names have template arguments.
X1(int)18 template<typename T> X1<T>::X1<T>(int) { } // expected-error{{out-of-line constructor for 'X1' cannot have template arguments}}
19 template<typename T> (X1<T>::X1<T>)(float) { } // expected-error{{out-of-line constructor for 'X1' cannot have template arguments}}
20
21 // Error recovery: out-of-line constructor names intended to be types
f1()22 X0::X0 X0::f1() { return X0(); } // expected-error{{qualified reference to 'X0' is a constructor name rather than a type wherever a constructor can be declared}}
23
f2()24 struct X0::X0 X0::f2() { return X0(); }
25
f2()26 template<typename T> X1<T>::X1<T> X1<T>::f2() { } // expected-error{{qualified reference to 'X1' is a constructor name rather than a template name wherever a constructor can be declared}}
X1(X1<T>::f2)27 template<typename T> X1<T>::X1<T> (X1<T>::f2)(int) { } // expected-error{{qualified reference to 'X1' is a constructor name rather than a template name wherever a constructor can be declared}}
X1(X1<T>::f2)28 template<typename T> struct X1<T>::X1<T> (X1<T>::f2)(float) { }
29
30 // We have a special case for lookup within using-declarations that are
31 // member-declarations: foo::bar::baz::baz always names baz's constructor
32 // in such a context, even if looking up 'baz' within foo::bar::baz would
33 // not find the injected-class-name. Likewise foo::bar::baz<T>::baz also
34 // names the constructor.
35 namespace InhCtor {
36 struct A {
37 A(int);
38 protected:
39 int T();
40 };
41 typedef A T;
42 struct B : A {
43 // This is a using-declaration for 'int A::T()' in C++98, but is an
44 // inheriting constructor declaration in C++11.
45 using InhCtor::T::T;
46 };
47 #if __cplusplus < 201103L
48 B b(123); // expected-error {{no matching constructor}}
49 // expected-note@-7 2{{candidate constructor}}
50 int n = b.T(); // ok, accessible
51 #else
52 B b(123); // ok, inheriting constructor
53 int n = b.T(); // expected-error {{'T' is a protected member of 'InhCtor::A'}}
54 // expected-note@-15 {{declared protected here}}
55
56 // FIXME: EDG and GCC reject this too, but it's not clear why it would be
57 // ill-formed.
58 template<typename T>
59 struct S : T {
60 struct U : S { // expected-note 6{{candidate}}
61 using S::S;
62 };
63 using T::T;
64 };
65 S<A>::U ua(0); // expected-error {{no match}}
66 S<B>::U ub(0); // expected-error {{no match}}
67
68 template<typename T>
69 struct X : T {
70 using T::Z::U::U;
71 };
72 template<typename T>
73 struct X2 : T {
74 using T::Z::template V<int>::V;
75 };
76 struct Y {
77 struct Z {
78 typedef Y U;
79 template<typename T> using V = Y;
80 };
81 Y(int);
82 };
83 X<Y> xy(0);
84
85 namespace Repeat {
86 struct A {
87 struct T {
88 T(int);
89 };
90 };
91 struct Z : A {
92 using A::A::A;
93 };
94 template<typename T>
95 struct ZT : T::T {
96 using T::T::T;
97 };
98 }
99
100 namespace NS {
101 struct NS {};
102 }
103 struct DerivedFromNS : NS::NS {
104 // No special case unless the NNS names a class.
105 using InhCtor::NS::NS; // expected-error {{using declaration in class refers into 'InhCtor::NS::', which is not a class}}
106
107 };
108
109 // FIXME: Consider reusing the same diagnostic between dependent and non-dependent contexts
110 typedef int I;
111 struct UsingInt {
112 using I::I; // expected-error {{'I' (aka 'int') is not a class, namespace, or enumeration}}
113 };
114 template<typename T> struct UsingIntTemplate {
115 using T::T; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
116 };
117 UsingIntTemplate<int> uit; // expected-note {{here}}
118 #endif
119 }
120