xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/union-dtor.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++11 %s -S -o - -emit-llvm | FileCheck %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // PR10304: destructors should not call destructors for variant members.
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc template<bool b = false>
6*f4a2713aSLionel Sambuc struct Foo {
FooFoo7*f4a2713aSLionel Sambuc   Foo() { static_assert(b, "Foo::Foo used"); }
~FooFoo8*f4a2713aSLionel Sambuc   ~Foo() { static_assert(b, "Foo::~Foo used"); }
9*f4a2713aSLionel Sambuc };
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc struct Bar {
12*f4a2713aSLionel Sambuc   Bar();
13*f4a2713aSLionel Sambuc   ~Bar();
14*f4a2713aSLionel Sambuc };
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc union FooBar {
FooBar()17*f4a2713aSLionel Sambuc   FooBar() {}
~FooBar()18*f4a2713aSLionel Sambuc   ~FooBar() {}
19*f4a2713aSLionel Sambuc   Foo<> foo;
20*f4a2713aSLionel Sambuc   Bar bar;
21*f4a2713aSLionel Sambuc };
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc struct Variant {
VariantVariant24*f4a2713aSLionel Sambuc   Variant() {}
~VariantVariant25*f4a2713aSLionel Sambuc   ~Variant() {}
26*f4a2713aSLionel Sambuc   union {
27*f4a2713aSLionel Sambuc     Foo<> foo;
28*f4a2713aSLionel Sambuc     Bar bar;
29*f4a2713aSLionel Sambuc   };
30*f4a2713aSLionel Sambuc };
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc FooBar foobar;
33*f4a2713aSLionel Sambuc Variant variant;
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc // The ctor and dtor of Foo<> and Bar should not be mentioned in the resulting
36*f4a2713aSLionel Sambuc // code.
37*f4a2713aSLionel Sambuc //
38*f4a2713aSLionel Sambuc // CHECK-NOT: 3FooILb1EEC1
39*f4a2713aSLionel Sambuc // CHECK-NOT: 3BarC1
40*f4a2713aSLionel Sambuc //
41*f4a2713aSLionel Sambuc // CHECK-NOT: 3FooILb1EED1
42*f4a2713aSLionel Sambuc // CHECK-NOT: 3BarD1
43