blob: d1562d4cd18b3da501fb3c18e0f218a8addc34ed [file] [log] [blame]
Richard Smith2db075b2013-03-26 01:15:19 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
Douglas Gregor0efc2c12010-01-13 17:31:36 +00003struct X0 {
4 X0 f1();
5 X0 f2();
6};
7
8template<typename T>
9struct 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.
18template<typename T> X1<T>::X1<T>(int) { } // expected-error{{out-of-line constructor for 'X1' cannot have template arguments}}
19template<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
22X0::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
24struct X0::X0 X0::f2() { return X0(); }
25
26template<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}}
27template<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}}
28template<typename T> struct X1<T>::X1<T> (X1<T>::f2)(float) { }
Richard Smith2db075b2013-03-26 01:15:19 +000029
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.
35namespace 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 template<typename T>
57 struct S : T {
58 struct U : S {
59 using S::S;
60 };
61 using T::T;
62 };
63
64 S<A>::U ua(0);
65 S<B>::U ub(0);
66
67 template<typename T>
68 struct X : T {
69 using T::Z::U::U;
70 };
71 template<typename T>
72 struct X2 : T {
73 using T::Z::template V<int>::V;
74 };
75 struct Y {
76 struct Z {
77 typedef Y U;
78 template<typename T> using V = Y;
79 };
80 Y(int);
81 };
82 X<Y> xy(0);
83
84 namespace Repeat {
85 struct A {
86 struct T {
87 T(int);
88 };
89 };
90 struct Z : A {
Richard Smith2db075b2013-03-26 01:15:19 +000091 using A::A::A;
92 };
93 template<typename T>
94 struct ZT : T::T {
Richard Smith2db075b2013-03-26 01:15:19 +000095 using T::T::T;
96 };
97 }
98
99 namespace NS {
100 struct NS {};
101 }
102 struct DerivedFromNS : NS::NS {
103 // No special case unless the NNS names a class.
104 using InhCtor::NS::NS; // expected-error {{using declaration in class refers into 'InhCtor::NS::', which is not a class}}
105
106 };
107
Stephen Hines651f13c2014-04-23 16:59:28 -0700108 // FIXME: Consider reusing the same diagnostic between dependent and non-dependent contexts
Richard Smith2db075b2013-03-26 01:15:19 +0000109 typedef int I;
110 struct UsingInt {
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700111 using I::I; // expected-error {{'I' (aka 'int') is not a class, namespace, or enumeration}}
Richard Smith2db075b2013-03-26 01:15:19 +0000112 };
113 template<typename T> struct UsingIntTemplate {
114 using T::T; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
115 };
116 UsingIntTemplate<int> uit; // expected-note {{here}}
117#endif
118}