• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 namespace 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 
19 namespace 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 
25 namespace 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 
33 namespace 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 
60 namespace 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 {{unknown type name 'U'}}
67     static int (k)() throw(U);
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 
77 namespace PR12688 {
78   struct S {
79     // FIXME: Maybe suppress the "constructor cannot have a return type" error
80     // if the return type is invalid.
81     nonsense S() throw (more_nonsense); // \
82     // expected-error {{'nonsense'}} \
83     // expected-error {{constructor cannot have a return type}}
84   };
85 }
86