// RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s template struct A; // expected-note {{template is declared here}} \ // expected-note{{explicitly specialized}} template<> struct A; // expected-note{{forward declaration}} template<> struct A { // expected-note{{previous definition}} int x; }; template<> struct A { // expected-note{{previous definition}} int y; }; int test_specs(A *a1, A *a2) { return a1->x + a2->y; } int test_incomplete_specs(A *a1, A *a2) { (void)a1->x; // expected-error{{member access into incomplete type}} (void)a2->x; // expected-error{{implicit instantiation of undefined template 'A'}} } typedef float FLOAT; template<> struct A; template<> struct A { }; // expected-error{{redefinition}} template<> struct A { }; // expected-error{{redefinition}} template struct X; template <> struct X { int foo(); }; // #1 template <> struct X { int bar(); }; // #2 typedef int int_type; void testme(X *x1, X *x2) { (void)x1->foo(); // okay: refers to #1 (void)x2->bar(); // okay: refers to #2 } // Make sure specializations are proper classes. template<> struct A { A(); }; A::A() { } // Make sure we can see specializations defined before the primary template. namespace N{ template struct A0; } namespace N { template<> struct A0 { typedef void* pointer; }; } namespace N { template struct A0 { void foo(A0::pointer p = 0); }; } // Diagnose specialization errors struct A { }; // expected-error{{template specialization requires 'template<>'}} template<> struct ::A; namespace N { template struct B; // expected-note {{explicitly specialized}} #if __cplusplus <= 199711L // expected-note@-2 {{explicitly specialized}} #endif template<> struct ::N::B; // okay template<> struct ::N::B; // okay template<> struct ::N::B; // okay int f(int); } template<> struct N::B { }; // okay template<> struct N::B { }; #if __cplusplus <= 199711L // expected-warning@-2 {{first declaration of class template specialization of 'B' outside namespace 'N' is a C++11 extension}} #endif namespace M { template<> struct ::N::B { }; // expected-error{{class template specialization of 'B' not in a namespace enclosing 'N'}} template<> struct ::A; // expected-error{{must occur at global scope}} } template<> struct N::B { int testf(int x) { return f(x); } }; // PR5264 template class Foo; Foo* v; Foo& F() { return *v; } template class Foo {}; Foo x; // Template template parameters template class Wibble> class Wibble { }; // expected-error{{cannot specialize a template template parameter}} namespace rdar9676205 { template struct X { template struct X { // expected-error{{explicit specialization of 'X' in class scope}} }; }; } namespace PR18009 { template struct A { template struct S; template struct S {}; }; A::S<8, sizeof(int)> a; // ok template struct B { template struct S; template struct S {}; // ok (dr1315) }; B::S<8, sizeof(int) + 8> b; template struct C { template struct S; template struct S {}; // expected-error {{depends on a template parameter of the partial specialization}} }; C c; // expected-note {{in instantiation of}} template struct outer { template struct inner {}; template struct inner {}; }; } namespace PR16519 { template struct integer_sequence { typedef T value_type; }; #if __cplusplus <= 199711L // expected-warning@-2 {{variadic templates are a C++11 extension}} #endif template struct __make_integer_sequence; template using make_integer_sequence = typename __make_integer_sequence::template make::type; #if __cplusplus <= 199711L // expected-warning@-2 {{alias declarations are a C++11 extension}} #endif template struct __make_integer_sequence_impl; #if __cplusplus <= 199711L // expected-warning@-2 {{variadic templates are a C++11 extension}} #endif // Note that the following seemingly-equivalent template parameter list is // not OK; it would result in a partial specialization that is not more // specialized than the primary template. (See NTTPTypeVsPartialOrder below.) // // template template::value_type ...Extra> #if __cplusplus <= 199711L // expected-warning@-2 2{{variadic templates are a C++11 extension}} #endif struct __make_integer_sequence_impl, Extra...> { typedef integer_sequence type; }; template struct __make_integer_sequence { template struct make; template struct make<0, 0, Dummy> { typedef integer_sequence type; }; template struct make<1, 1, Dummy> { typedef integer_sequence type; }; template struct make : __make_integer_sequence_impl > {}; template struct make : __make_integer_sequence_impl, N - 1> {}; }; using X = make_integer_sequence; #if __cplusplus <= 199711L // expected-warning@-2 {{alias declarations are a C++11 extension}} #endif using X = integer_sequence; #if __cplusplus <= 199711L // expected-warning@-2 {{alias declarations are a C++11 extension}} #endif } namespace NTTPTypeVsPartialOrder { struct X { typedef int value_type; }; template struct Y { typedef T value_type; }; template struct A; template struct A {}; template struct A, N> {}; A ax; A, 0> ay; template struct B; template struct B<0, T, N>; template struct B<0, X, N> {}; template struct B<0, Y, N> {}; B<0, X, 0> bx; B<0, Y, 0> by; } namespace DefaultArgVsPartialSpec { // Check that the diagnostic points at the partial specialization, not just at // the default argument. template struct X {}; template struct X {}; template struct S; template struct S {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'T'}} }