xref: /minix3/external/bsd/llvm/dist/clang/test/CXX/class/class.mem/p2.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc // C++11 [class.mem]p2:
4f4a2713aSLionel Sambuc //   A class is considered a completely-defined object type (or
5f4a2713aSLionel Sambuc //   complete type) at the closing } of the class-specifier. Within
6f4a2713aSLionel Sambuc //   the class member-specification, the class is regarded as complete
7f4a2713aSLionel Sambuc //   within function bodies, default arguments,
8f4a2713aSLionel Sambuc //   exception-specifications, and brace-or-equal-initializers for
9f4a2713aSLionel Sambuc //   non-static data members (including such things in nested classes).
10f4a2713aSLionel Sambuc //   Otherwise it is regarded as incomplete within its own class
11f4a2713aSLionel Sambuc //   member-specification.
12f4a2713aSLionel Sambuc 
13f4a2713aSLionel Sambuc namespace test0 {
14f4a2713aSLionel Sambuc   struct A { // expected-note {{definition of 'test0::A' is not complete until the closing '}'}}
15f4a2713aSLionel Sambuc     A x; // expected-error {{field has incomplete type 'test0::A'}}
16f4a2713aSLionel Sambuc   };
17f4a2713aSLionel Sambuc }
18f4a2713aSLionel Sambuc 
19f4a2713aSLionel Sambuc namespace test1 {
20f4a2713aSLionel Sambuc   template <class T> struct A {
21f4a2713aSLionel Sambuc     A<int> x; // expected-error {{implicit instantiation of template 'test1::A<int>' within its own definition}}
22f4a2713aSLionel Sambuc   };
23f4a2713aSLionel Sambuc }
24f4a2713aSLionel Sambuc 
25f4a2713aSLionel Sambuc namespace test2 {
26f4a2713aSLionel Sambuc   template <class T> struct A;
27f4a2713aSLionel Sambuc   template <> struct A<int> {};
28f4a2713aSLionel Sambuc   template <class T> struct A {
29f4a2713aSLionel Sambuc     A<int> x;
30f4a2713aSLionel Sambuc   };
31f4a2713aSLionel Sambuc }
32f4a2713aSLionel Sambuc 
33f4a2713aSLionel Sambuc namespace test3 {
34f4a2713aSLionel Sambuc   struct A {
35f4a2713aSLionel Sambuc     struct B {
36f4a2713aSLionel Sambuc       void f() throw(A);
37f4a2713aSLionel Sambuc       void g() throw(B);
38f4a2713aSLionel Sambuc     };
39f4a2713aSLionel Sambuc 
40f4a2713aSLionel Sambuc     void f() throw(A);
41f4a2713aSLionel Sambuc     void g() throw(B);
42f4a2713aSLionel Sambuc   };
43f4a2713aSLionel Sambuc 
44f4a2713aSLionel Sambuc   template<typename T>
45f4a2713aSLionel Sambuc   struct A2 {
46f4a2713aSLionel Sambuc     struct B {
47f4a2713aSLionel Sambuc       void f1() throw(A2);
48f4a2713aSLionel Sambuc       void f2() throw(A2<T>);
49f4a2713aSLionel Sambuc       void g() throw(B);
50f4a2713aSLionel Sambuc     };
51f4a2713aSLionel Sambuc 
52f4a2713aSLionel Sambuc     void f1() throw(A2);
53f4a2713aSLionel Sambuc     void f2() throw(A2<T>);
54f4a2713aSLionel Sambuc     void g() throw(B);
55f4a2713aSLionel Sambuc   };
56f4a2713aSLionel Sambuc 
57f4a2713aSLionel Sambuc   template struct A2<int>;
58f4a2713aSLionel Sambuc }
59*0a6a1f1dSLionel Sambuc 
60*0a6a1f1dSLionel Sambuc namespace PR12629 {
61*0a6a1f1dSLionel Sambuc   struct S {
62*0a6a1f1dSLionel Sambuc     static int (f)() throw();
63*0a6a1f1dSLionel Sambuc     static int ((((((g))))() throw(U)));
64*0a6a1f1dSLionel Sambuc     int (*h)() noexcept(false);
65*0a6a1f1dSLionel Sambuc     static int (&i)() noexcept(true);
66*0a6a1f1dSLionel Sambuc     static int (*j)() throw(U); // expected-error {{unknown type name 'U'}}
67*0a6a1f1dSLionel Sambuc     static int (k)() throw(U);
68*0a6a1f1dSLionel Sambuc 
69*0a6a1f1dSLionel Sambuc     struct U {};
70*0a6a1f1dSLionel Sambuc   };
71*0a6a1f1dSLionel Sambuc   static_assert(noexcept(S::f()), "");
72*0a6a1f1dSLionel Sambuc   static_assert(!noexcept(S::g()), "");
73*0a6a1f1dSLionel Sambuc   static_assert(!noexcept(S().h()), "");
74*0a6a1f1dSLionel Sambuc   static_assert(noexcept(S::i()), "");
75*0a6a1f1dSLionel Sambuc }
76*0a6a1f1dSLionel Sambuc 
77*0a6a1f1dSLionel Sambuc namespace PR12688 {
78*0a6a1f1dSLionel Sambuc   struct S {
79*0a6a1f1dSLionel Sambuc     // FIXME: Producing one error saying this can't have the same name
80*0a6a1f1dSLionel Sambuc     //        as the class because it's not a constructor, then producing
81*0a6a1f1dSLionel Sambuc     //        another error saying this can't have a return type because
82*0a6a1f1dSLionel Sambuc     //        it is a constructor, is redundant and inconsistent.
83*0a6a1f1dSLionel Sambuc     nonsense S() throw (more_nonsense); // \
84*0a6a1f1dSLionel Sambuc     // expected-error {{'nonsense'}} \
85*0a6a1f1dSLionel Sambuc     // expected-error {{has the same name as its class}} \
86*0a6a1f1dSLionel Sambuc     // expected-error {{constructor cannot have a return type}}
87*0a6a1f1dSLionel Sambuc   };
88*0a6a1f1dSLionel Sambuc }
89