xref: /aosp_15_r20/external/clang/test/SemaTemplate/instantiate-member-initializers.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -Wall -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li template<typename T> struct A {
AA4*67e74705SXin Li   A() : a(1) { } // expected-error{{cannot initialize a member subobject of type 'void *' with an rvalue of type 'int'}}
5*67e74705SXin Li 
6*67e74705SXin Li   T a;
7*67e74705SXin Li };
8*67e74705SXin Li 
9*67e74705SXin Li A<int> a0;
10*67e74705SXin Li A<void*> a1; // expected-note{{in instantiation of member function 'A<void *>::A' requested here}}
11*67e74705SXin Li 
12*67e74705SXin Li template<typename T> struct B {
BB13*67e74705SXin Li   B() : b(1), // expected-warning {{field 'b' will be initialized after field 'a'}}
14*67e74705SXin Li     a(2) { }
15*67e74705SXin Li 
16*67e74705SXin Li   int a;
17*67e74705SXin Li   int b;
18*67e74705SXin Li };
19*67e74705SXin Li 
20*67e74705SXin Li B<int> b0; // expected-note {{in instantiation of member function 'B<int>::B' requested here}}
21*67e74705SXin Li 
22*67e74705SXin Li template <class T> struct AA { AA(int); };
23*67e74705SXin Li template <class T> class BB : public AA<T> {
24*67e74705SXin Li public:
BB()25*67e74705SXin Li   BB() : AA<T>(1) {}
26*67e74705SXin Li };
27*67e74705SXin Li BB<int> x;
28*67e74705SXin Li 
29*67e74705SXin Li struct X {
30*67e74705SXin Li   X();
31*67e74705SXin Li };
32*67e74705SXin Li template<typename T>
33*67e74705SXin Li struct Y {
YY34*67e74705SXin Li   Y() : x() {}
35*67e74705SXin Li   X x;
36*67e74705SXin Li };
37*67e74705SXin Li Y<int> y;
38*67e74705SXin Li 
39*67e74705SXin Li template<typename T> struct Array {
40*67e74705SXin Li   int a[3];
ArrayArray41*67e74705SXin Li   Array() : a() {}
42*67e74705SXin Li };
43*67e74705SXin Li Array<int> s;
44