// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s struct X0 { X0(); X0(int); X0 f1(); X0 f2(); typedef int A; typedef X0 B; }; template struct X1 : X0 { X1(); X1(int); (X1)(float); X1 f2(); X1 f2(int); X1 f2(float); X1 f2(double); X1 f2(short); X1 f2(long); }; // Error recovery: out-of-line constructors whose names have template arguments. template X1::X1(int) { } // expected-error{{out-of-line constructor for 'X1' cannot have template arguments}} template (X1::X1)(float) { } // expected-error{{out-of-line constructor for 'X1' cannot have template arguments}} // Error recovery: out-of-line constructor names intended to be types X0::X0 X0::f1() { return X0(); } // expected-error{{qualified reference to 'X0' is a constructor name rather than a type in this context}} struct X0::X0 X0::f2() { return X0(); } template X1::X1 X1::f2() { } // expected-error{{missing 'typename'}} template X1::X1 (X1::f2)(int) { } // expected-error{{missing 'typename'}} template struct X1::X1 (X1::f2)(float) { } template struct X1::X1 (X1::f2)(double) { } template typename X1::template X1 X1::f2(short) { } // expected-warning {{qualified reference to 'X1' is a constructor name rather than a template name in this context}} template typename X1::template X1 (X1::f2)(long) { } // expected-warning {{qualified reference to 'X1' is a constructor name rather than a template name in this context}} void x1test(X1 x1i) { x1i.f2(); x1i.f2(0); x1i.f2(0.f); x1i.f2(0.); } void other_contexts() { X0::X0 x0; // expected-error{{qualified reference to 'X0' is a constructor name rather than a type in this context}} X1::X1 x1a; // expected-error{{qualified reference to 'X1' is a constructor name rather than a type in this context}} X1::X1 x1b; // expected-error{{qualified reference to 'X1' is a constructor name rather than a template name in this context}} X0::B ok1; X0::X0::A ok2; X0::X0::X0 x0b; // expected-error{{qualified reference to 'X0' is a constructor name rather than a type in this context}} X1::X0 ok3; X1::X0::X0 x0c; // expected-error{{qualified reference to 'X0' is a constructor name rather than a type in this context}} X1::X1::X0 ok4; { 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}} typename X1::X1 tn2; // expected-warning{{qualified reference to 'X1' is a constructor name rather than a template name in this context}} expected-warning 0-1{{typename}} typename X0::B ok1; // expected-warning 0-1{{typename}} typename X1::X0 ok2; // expected-warning 0-1{{typename}} } { struct X0::X0 tag1; struct X1::X1 tag2; struct X1::X1 tag3; } int a; { X0::X0(a); // expected-error{{qualified reference to 'X0' is a constructor name rather than a type in this context}} // expected-warning@-1 {{redundant parentheses around declaration of variable named 'a'}} expected-note@-1 2{{}} } } template void in_instantiation_x0() { typename T::X0 x0; // expected-warning{{qualified reference to 'X0' is a constructor name rather than a type in this context}} typename T::A a; typename T::B b; } template void in_instantiation_x0(); // expected-note {{instantiation of}} template void in_instantiation_x1() { typename T::X1 x1; // expected-warning{{qualified reference to 'X1' is a constructor name rather than a type in this context}} typename T::template X1 x1i; // expected-warning{{qualified reference to 'X1' is a constructor name rather than a template name in this context}} typename T::X0 x0; } template void in_instantiation_x1 >(); // expected-note {{instantiation of}} namespace sfinae { template void f(typename T::X0 *) = delete; // expected-warning 0-1{{extension}} template void f(...); void g() { f(0); } } namespace versus_injected_class_name { template struct A : T::B { struct T::B *p; typename T::B::type a; A() : T::B() {} typename T::B b; // expected-warning {{qualified reference to 'B' is a constructor name rather than a type in this context}} }; struct B { typedef int type; }; template struct A; // expected-note {{in instantiation of}} } // We have a special case for lookup within using-declarations that are // member-declarations: foo::bar::baz::baz always names baz's constructor // in such a context, even if looking up 'baz' within foo::bar::baz would // not find the injected-class-name. Likewise foo::bar::baz::baz also // names the constructor. namespace InhCtor { struct A { A(int); protected: int T(); }; typedef A T; struct B : A { // This is a using-declaration for 'int A::T()' in C++98, but is an // inheriting constructor declaration in C++11. using InhCtor::T::T; }; #if __cplusplus < 201103L B b(123); // expected-error {{no matching constructor}} // expected-note@-7 2{{candidate constructor}} int n = b.T(); // ok, accessible #else B b(123); // ok, inheriting constructor int n = b.T(); // expected-error {{'T' is a protected member of 'InhCtor::A'}} // expected-note@-15 {{declared protected here}} // FIXME: EDG and GCC reject this too, but it's not clear why it would be // ill-formed. template struct S : T { struct U : S { // expected-note 6{{candidate}} using S::S; }; using T::T; }; S::U ua(0); // expected-error {{no match}} S::U ub(0); // expected-error {{no match}} template struct X : T { using T::Z::U::U; }; template struct X2 : T { using T::Z::template V::V; }; struct Y { struct Z { typedef Y U; template using V = Y; }; Y(int); }; X xy(0); namespace Repeat { struct A { struct T { T(int); }; }; struct Z : A { using A::A::A; }; template struct ZT : T::T { using T::T::T; }; } namespace NS { struct NS {}; } struct DerivedFromNS : NS::NS { // No special case unless the NNS names a class. using InhCtor::NS::NS; // expected-error {{using declaration in class refers into 'InhCtor::NS::', which is not a class}} }; // FIXME: Consider reusing the same diagnostic between dependent and non-dependent contexts typedef int I; struct UsingInt { using I::I; // expected-error {{'InhCtor::I' (aka 'int') is not a class, namespace, or enumeration}} }; template struct UsingIntTemplate { using T::T; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} }; UsingIntTemplate uit; // expected-note {{here}} // This case is odd: we don't name the constructor of a dependent base as // Base::Base, but we still happen to have enough information to identify // when parsing the template that we're inheriting constructors. // // FIXME: Once CWG 2070 is resolved, check whether this case should be // accepted or not. namespace DependentCtorName { template struct B { B(int); }; template struct A : B { using X = B; using X::B; }; A ab = 0; } #endif }