1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
5 non_trivial(const non_trivial
&);
6 non_trivial
& operator = (const non_trivial
&);
20 union static_data_member
{
23 int static_data_member::i
;
26 int &i
; // expected-error {{union member 'i' has reference type 'int &'}}
35 // Don't crash on this.
36 struct TemplateCtor
{ template<typename T
> TemplateCtor(T
); };
37 union TemplateCtorMember
{ TemplateCtor s
; };
39 template<typename T
> struct remove_ref
{ typedef T type
; };
40 template<typename T
> struct remove_ref
<T
&> { typedef T type
; };
41 template<typename T
> struct remove_ref
<T
&&> { typedef T type
; };
42 template<typename T
> T
&&forward(typename remove_ref
<T
>::type
&&t
);
43 template<typename T
> T
&&forward(typename remove_ref
<T
>::type
&t
);
44 template<typename T
> typename remove_ref
<T
>::type
&&move(T
&&t
);
46 using size_t = decltype(sizeof(int));
47 void *operator new(size_t, void *p
) noexcept
{ return p
; }
49 namespace disabled_dtor
{
53 template<typename
...U
>
54 disable_dtor(U
&&...u
) : val(forward
<U
>(u
)...) {}
59 deleted_dtor(int n
, char c
) : n(n
), c(c
) {}
62 ~deleted_dtor() = delete;
65 disable_dtor
<deleted_dtor
> dd(4, 'x');
69 template<typename T
> struct optional
{
73 optional() : has(false) {}
74 template<typename
...U
>
75 optional(U
&&...u
) : has(true), value(forward
<U
>(u
)...) {}
77 optional(const optional
&o
) : has(o
.has
) {
78 if (has
) new (&value
) T(o
.value
);
80 optional(optional
&&o
) : has(o
.has
) {
81 if (has
) new (&value
) T(move(o
.value
));
84 optional
&operator=(const optional
&o
) {
91 new (&value
) T(o
.value
);
95 optional
&operator=(optional
&&o
) {
98 value
= move(o
.value
);
102 new (&value
) T(move(o
.value
));
112 explicit operator bool() const { return has
; }
113 T
&operator*() { return value
; }
116 optional
<non_trivial
> o1
;
117 optional
<non_trivial
> o2
{non_trivial()};
118 optional
<non_trivial
> o3
{*o2
};
122 o2
= optional
<non_trivial
>();
129 template<typename T
> struct Test1
{
137 template<typename T
> struct Test2
{
139 struct { // expected-note-re {{default constructor of 'Test2<pr16061::X>' is implicitly deleted because variant field 'struct (anonymous struct at{{.+}})' has a non-trivial default constructor}}
145 Test2
<X
> t2x
; // expected-error {{call to implicitly-deleted default constructor of 'Test2<X>'}}
150 struct non_trivial_constructor
{
151 constexpr non_trivial_constructor() : x(100) {}
158 non_trivial_constructor b
; // expected-note {{has a non-trivial default constructor}}
163 non_trivial_constructor b
;
168 non_trivial_constructor b
{};
172 int a
{}; // expected-note {{previous initialization is here}}
173 non_trivial_constructor b
{}; // expected-error {{initializing multiple members of union}}
176 U1 u1
; // expected-error {{call to implicitly-deleted default constructor}}
181 static_assert(U2().a
== 1000, "");
182 static_assert(U3().a
== 1000, "");
183 // expected-error@-1 {{static assertion expression is not an integral constant expression}}
184 // expected-note@-2 {{read of member 'a' of union with active member 'b'}}
185 static_assert(U2().b
.x
== 100, "");
186 // expected-error@-1 {{static assertion expression is not an integral constant expression}}
187 // expected-note@-2 {{read of member 'b' of union with active member 'a'}}
188 static_assert(U3().b
.x
== 100, "");
190 } // namespace GH48416