p2.cpp revision 2b2a0876c9d3a92c5216a578373817974fe159a0
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 2 3// C++11 [class.mem]p2: 4// A class is considered a completely-defined object type (or 5// complete type) at the closing } of the class-specifier. Within 6// the class member-specification, the class is regarded as complete 7// within function bodies, default arguments, 8// exception-specifications, and brace-or-equal-initializers for 9// non-static data members (including such things in nested classes). 10// Otherwise it is regarded as incomplete within its own class 11// member-specification. 12 13namespace test0 { 14 struct A { // expected-note {{definition of 'test0::A' is not complete until the closing '}'}} 15 A x; // expected-error {{field has incomplete type 'test0::A'}} 16 }; 17} 18 19namespace test1 { 20 template <class T> struct A { 21 A<int> x; // expected-error {{implicit instantiation of template 'test1::A<int>' within its own definition}} 22 }; 23} 24 25namespace test2 { 26 template <class T> struct A; 27 template <> struct A<int> {}; 28 template <class T> struct A { 29 A<int> x; 30 }; 31} 32 33namespace test3 { 34 struct A { 35 struct B { 36 void f() throw(A); 37 void g() throw(B); 38 }; 39 40 void f() throw(A); 41 void g() throw(B); 42 }; 43 44 template<typename T> 45 struct A2 { 46 struct B { 47 void f1() throw(A2); 48 void f2() throw(A2<T>); 49 void g() throw(B); 50 }; 51 52 void f1() throw(A2); 53 void f2() throw(A2<T>); 54 void g() throw(B); 55 }; 56 57 template struct A2<int>; 58} 59 60namespace PR12629 { 61 struct S { 62 static int (f)() throw(); 63 static int ((((((g))))() throw(U))); 64 int (*h)() noexcept(false); 65 static int (&i)() noexcept(true); 66 static int (*j)() throw(U); // expected-error {{type name}} \ 67 // expected-error {{expected ')'}} expected-note {{to match}} 68 69 struct U {}; 70 }; 71 static_assert(noexcept(S::f()), ""); 72 static_assert(!noexcept(S::g()), ""); 73 static_assert(!noexcept(S().h()), ""); 74 static_assert(noexcept(S::i()), ""); 75} 76