1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
25 // Error recovery: out-of-line constructors whose names have template arguments.
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}}
29 // Error recovery: out-of-line constructor names intended to be types
30 X0::X0
X0::f1() { return X0(); } // expected-error{{qualified reference to 'X0' is a constructor name rather than a type in this context}}
32 struct X0::X0
X0::f2() { return X0(); }
34 template<typename T
> X1
<T
>::X1
<T
> X1
<T
>::f2() { } // expected-warning{{missing 'typename'}}
35 template<typename T
> X1
<T
>::X1
<T
> (X1
<T
>::f2
)(int) { } // expected-warning{{missing 'typename'}}
36 template<typename T
> struct X1
<T
>::X1
<T
> (X1
<T
>::f2
)(float) { }
37 template<typename T
> struct X1
<T
>::X1 (X1
<T
>::f2
)(double) { }
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}}
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}}
41 void x1test(X1
<int> x1i
) {
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}}
55 X0::X0::X0 x0b
; // expected-error{{qualified reference to 'X0' is a constructor name rather than a type in this context}}
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
;
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}}
69 struct X1
<int>::X1 tag2
;
70 struct X1
<int>::X1
<int> tag3
;
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{{}}
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}}
85 template void in_instantiation_x0
<X0
>(); // expected-note {{instantiation of}}
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}}
92 template void in_instantiation_x1
<X1
<int> >(); // expected-note {{instantiation of}}
95 template<typename T
> void f(typename
T::X0
*) = delete; // expected-warning 0-1{{extension}}
96 template<typename T
> void f(...);
97 void g() { f
<X0
>(0); }
100 namespace versus_injected_class_name
{
101 template <typename T
> struct A
: T::B
{
103 typename
T::B::type a
;
106 typename
T::B b
; // expected-warning {{qualified reference to 'B' is a constructor name rather than a type in this context}}
111 template struct A
<B
>; // expected-note {{in instantiation of}}
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.
127 // This is a using-declaration for 'int A::T()' in C++98, but is an
128 // inheriting constructor declaration in C++11.
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
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}}
140 // FIXME: EDG and GCC reject this too, but it's not clear why it would be
144 struct U
: S
{ // expected-note 6{{candidate}}
149 S
<A
>::U
ua(0); // expected-error {{no match}}
150 S
<B
>::U
ub(0); // expected-error {{no match}}
158 using T::Z::template V
<int>::V
;
163 template<typename T
> using V
= Y
;
187 struct DerivedFromNS
: NS::NS
{
188 // No special case unless the NNS names a class.
189 using InhCtor::NS::NS
; // expected-error {{using declaration in class refers into 'InhCtor::NS::', which is not a class}}
193 // FIXME: Consider reusing the same diagnostic between dependent and non-dependent contexts
196 using I::I
; // expected-error {{'InhCtor::I' (aka 'int') is not a class, namespace, or enumeration}}
198 template<typename T
> struct UsingIntTemplate
{
199 using T::T
; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
201 UsingIntTemplate
<int> uit
; // expected-note {{here}}
203 // This case is odd: we don't name the constructor of a dependent base as
204 // Base::Base, but we still happen to have enough information to identify
205 // when parsing the template that we're inheriting constructors.
207 // FIXME: Once CWG 2070 is resolved, check whether this case should be
209 namespace DependentCtorName
{
210 template <typename T
> struct B
{ B(int); };
211 template <typename T
> struct A
: B
<T
> {