Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s |
| 2 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 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. |
| 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 |
| 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 | |
| 24 | struct X0::X0 X0::f2() { return X0(); } |
| 25 | |
| 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}} |
| 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}} |
| 28 | template<typename T> struct X1<T>::X1<T> (X1<T>::f2)(float) { } |
Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 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 | 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 Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 91 | using A::A::A; |
| 92 | }; |
| 93 | template<typename T> |
| 94 | struct ZT : T::T { |
Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 95 | 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 Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 108 | // FIXME: Consider reusing the same diagnostic between dependent and non-dependent contexts |
Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 109 | typedef int I; |
| 110 | struct UsingInt { |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 111 | using I::I; // expected-error {{'I' (aka 'int') is not a class, namespace, or enumeration}} |
Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 112 | }; |
| 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 | } |