1 // RUN: %clang_cc1 -std=c++1z -verify -triple i686-linux-gnu %s
3 template<typename T, typename U> struct same;
4 template<typename T> struct same<T, T> { ~same(); };
12 namespace NonPublicMembers {
15 int a; // expected-note {{declared protected here}}
20 int a; // expected-note 2{{declared private here}}
23 struct NonPublic3 : private A {}; // expected-note {{constrained by private inheritance}}
25 struct NonPublic4 : NonPublic2 {};
28 auto [a1] = NonPublic1(); // expected-error {{cannot decompose non-public member 'a' of 'NonPublicMembers::NonPublic1'}}
29 auto [a2] = NonPublic2(); // expected-error {{cannot decompose non-public member 'a' of 'NonPublicMembers::NonPublic2'}}
30 auto [a3] = NonPublic3(); // expected-error {{cannot decompose members of non-public base class 'A' of 'NonPublic3'}}
31 auto [a4] = NonPublic4(); // expected-error {{cannot decompose non-public member 'a' of 'NonPublicMembers::NonPublic4'}}
35 namespace AnonymousMember {
37 struct { // expected-note {{declared here}}
43 union { // expected-note {{declared here}}
49 auto [a1] = Struct(); // expected-error {{cannot decompose class type 'AnonymousMember::Struct' because it has an anonymous struct member}}
50 auto [a2] = Union(); // expected-error {{cannot decompose class type 'AnonymousMember::Union' because it has an anonymous union member}}
54 namespace MultipleClasses {
62 struct E : virtual A {};
63 struct F : A, E {}; // expected-warning {{direct base 'A' is inaccessible due to ambiguity}}
65 struct G : virtual A {};
70 struct K : I, virtual J {}; // expected-warning {{direct base 'MultipleClasses::I' is inaccessible due to ambiguity}}
72 struct L : virtual J {};
73 struct M : virtual J, L {};
76 auto [b] = B(); // expected-error {{cannot decompose class type 'B': both it and its base class 'A' have non-static data members}}
77 auto [d] = D(); // expected-error {{cannot decompose class type 'D': its base classes 'A' and 'MultipleClasses::C' have non-static data members}}
79 auto [f] = F(); // expected-error-re {{cannot decompose members of ambiguous base class 'A' of 'F':{{.*}}struct MultipleClasses::F -> struct A{{.*}}struct MultipleClasses::F -> struct MultipleClasses::E -> struct A}}
80 auto [h] = H(); // ok, only one (virtual) base subobject even though there are two paths to it
81 auto [k] = K(); // expected-error {{cannot decompose members of ambiguous base class 'MultipleClasses::I'}}
82 auto [m] = M(); // ok, all paths to I are through the same virtual base subobject J
84 same<decltype(m), int>();
88 namespace BindingTypes {
93 mutable volatile int mvi;
96 auto [i,r,f,mvi] = A();
98 same<decltype(i), int>();
99 same<decltype(r), int&>();
100 same<decltype(f), const float>();
101 same<decltype(mvi), volatile int>();
103 same<decltype((i)), int&>();
104 same<decltype((r)), int&>();
105 same<decltype((f)), const float&>();
106 same<decltype((mvi)), volatile int&>();
109 auto &&[i,r,f,mvi] = A();
111 same<decltype(i), int>();
112 same<decltype(r), int&>();
113 same<decltype(f), const float>();
114 same<decltype(mvi), volatile int>();
116 same<decltype((i)), int&>();
117 same<decltype((r)), int&>();
118 same<decltype((f)), const float&>();
119 same<decltype((mvi)), volatile int&>();
122 const auto [i,r,f,mvi] = A();
124 same<decltype(i), const int>();
125 same<decltype(r), int&>();
126 same<decltype(f), const float>();
127 same<decltype(mvi), volatile int>(); // not 'const volatile int', per expected resolution of DRxxx
129 same<decltype((i)), const int&>();
130 same<decltype((r)), int&>();
131 same<decltype((f)), const float&>();
132 same<decltype((mvi)), volatile int&>(); // not 'const volatile int&', per expected resolution of DRxxx
136 auto &[i,r,f,mvi] = CA(); // type of var is 'const A &'
138 same<decltype(i), const int>(); // not 'int', per expected resolution of DRxxx
139 same<decltype(r), int&>();
140 same<decltype(f), const float>();
141 same<decltype(mvi), volatile int>(); // not 'const volatile int', per expected resolution of DRxxx
143 same<decltype((i)), const int&>(); // not 'int&', per expected resolution of DRxxx
144 same<decltype((r)), int&>();
145 same<decltype((f)), const float&>();
146 same<decltype((mvi)), volatile int&>(); // not 'const volatile int&', per expected resolution of DRxxx
153 const auto [ci] = B();
154 volatile auto [vi] = B();
155 same<decltype(i), int>();
156 same<decltype(ci), int>();
157 same<decltype(vi), volatile int>();
162 struct S { unsigned long long x : 4, y : 32; int z; }; // expected-note 2{{here}}
165 unsigned long long &ra = a; // expected-error {{bit-field 'x'}}
166 unsigned long long &rb = b; // expected-error {{bit-field 'y'}}
169 // the type of the binding is the type of the field
170 same<decltype(a), unsigned long long>();
171 same<decltype(b), unsigned long long>();
173 // the type of the expression is an lvalue of the field type
174 // (even though a reference can't bind to the field)
175 same<decltype((a)), unsigned long long&>();
176 same<decltype((b)), unsigned long long&>();
178 // the expression promotes to a type large enough to hold the result
179 same<decltype(+a), int>();
180 same<decltype(+b), unsigned int>();
185 namespace Constexpr {
186 struct Q { int a, b; constexpr Q() : a(1), b(2) {} };
189 static_assert(&qa == &q.a && &qb == &q.b);
190 static_assert(qa == 1 && qb == 2);
193 namespace std_example {
194 struct S { int x1 : 2; volatile double y1; };
196 const auto [x, y] = f();
198 same<decltype((x)), const int&> same1;
199 same<decltype((y)), const volatile double&> same2;