xref: /llvm-project/clang/test/CXX/class.derived/class.derived.general/p2.cpp (revision acf5ad2a4ed9bf94b03d18ccddce7710e721dc6c)
1 // RUN: %clang_cc1 %s -fsyntax-only -verify
2 
3 namespace CurrentInstantiation {
4   template<typename T>
5   struct A0 { // expected-note 6{{definition of 'A0<T>' is not complete until the closing '}'}}
6     struct B0 : A0 { }; // expected-error {{base class has incomplete type}}
7 
8     template<typename U>
9     struct B1 : A0 { }; // expected-error {{base class has incomplete type}}
10 
11     struct B2;
12 
13     template<typename U>
14     struct B3;
15 
16     struct B4 { // expected-note 2{{definition of 'CurrentInstantiation::A0::B4' is not complete until the closing '}'}}
17       struct C0 : A0, B4 { }; // expected-error 2{{base class has incomplete type}}
18 
19       template<typename V>
20       struct C1 : A0, B4 { }; // expected-error 2{{base class has incomplete type}}
21 
22       struct C2;
23 
24       template<typename V>
25       struct C3;
26     };
27 
28     template<typename U>
29     struct B5 { // expected-note 2{{definition of 'B5<U>' is not complete until the closing '}'}}
30       struct C0 : A0, B5 { }; // expected-error 2{{base class has incomplete type}}
31 
32       template<typename V>
33       struct C1 : A0, B5 { }; // expected-error 2{{base class has incomplete type}}
34 
35       struct C2;
36 
37       template<typename V>
38       struct C3;
39     };
40   };
41 
42   template<typename T>
43   struct A0<T>::B2 : A0 { };
44 
45   template<typename T>
46   template<typename U>
47   struct A0<T>::B3 : A0 { };
48 
49   template<typename T>
50   struct A0<T>::B4::C2 : A0, B4 { };
51 
52   template<typename T>
53   template<typename V>
54   struct A0<T>::B4::C3 : A0, B4 { };
55 
56   template<typename T>
57   template<typename U>
58   struct A0<T>::B5<U>::C2 : A0, B5 { };
59 
60   template<typename T>
61   template<typename U>
62   template<typename V>
63   struct A0<T>::B5<U>::C3 : A0, B5 { };
64 
65   template<typename T>
66   struct A0<T*> { // expected-note 2{{definition of 'A0<type-parameter-0-0 *>' is not complete until the closing '}'}}
67     struct B0 : A0 { }; // expected-error {{base class has incomplete type}}
68 
69     template<typename U>
70     struct B1 : A0 { }; // expected-error {{base class has incomplete type}}
71 
72     struct B2;
73 
74     template<typename U>
75     struct B3;
76   };
77 
78   template<typename T>
79   struct A0<T*>::B2 : A0 { };
80 
81   template<typename T>
82   template<typename U>
83   struct A0<T*>::B3 : A0 { };
84 } // namespace CurrentInstantiation
85 
86 namespace MemberOfCurrentInstantiation {
87   template<typename T>
88   struct A0 {
89     struct B : B { }; // expected-error {{base class has incomplete type}}
90                       // expected-note@-1 {{definition of 'MemberOfCurrentInstantiation::A0::B' is not complete until the closing '}'}}
91 
92     template<typename U>
93     struct C : C<U> { }; // expected-error {{base class has incomplete type}}
94                          // expected-note@-1 {{definition of 'C<U>' is not complete until the closing '}'}}
95   };
96 
97   template<typename T>
98   struct A1 {
99     struct B; // expected-note {{definition of 'MemberOfCurrentInstantiation::A1<long>::B' is not complete until the closing '}'}}
100 
101     struct C : B { }; // expected-error {{base class has incomplete type}}
102 
103     struct B : C { }; // expected-note {{in instantiation of member class 'MemberOfCurrentInstantiation::A1<long>::C' requested here}}
104   };
105 
106   template struct A1<long>; // expected-note {{in instantiation of member class 'MemberOfCurrentInstantiation::A1<long>::B' requested here}}
107 
108   template<>
109   struct A1<short>::B {
fMemberOfCurrentInstantiation::A1::B110     static constexpr bool f() {
111       return true;
112     }
113   };
114 
115   static_assert(A1<short>::C::f());
116 } // namespace MemberOfCurrentInstantiation
117