xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/cxx0x-delegating-ctors.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -fexceptions -fcxx-exceptions -std=c++11 -o - %s | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc struct non_trivial {
4f4a2713aSLionel Sambuc   non_trivial();
5f4a2713aSLionel Sambuc   ~non_trivial() noexcept(false);
6f4a2713aSLionel Sambuc };
non_trivial()7f4a2713aSLionel Sambuc non_trivial::non_trivial() {}
~non_trivial()8f4a2713aSLionel Sambuc non_trivial::~non_trivial() noexcept(false) {}
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc // We use a virtual base to ensure that the constructor
11f4a2713aSLionel Sambuc // delegation optimization (complete->base) can't be
12f4a2713aSLionel Sambuc // performed.
13f4a2713aSLionel Sambuc struct delegator {
14f4a2713aSLionel Sambuc   non_trivial n;
15f4a2713aSLionel Sambuc   delegator();
16f4a2713aSLionel Sambuc   delegator(int);
17f4a2713aSLionel Sambuc   delegator(char);
18f4a2713aSLionel Sambuc   delegator(bool);
19f4a2713aSLionel Sambuc };
20f4a2713aSLionel Sambuc 
delegator()21f4a2713aSLionel Sambuc delegator::delegator() {
22f4a2713aSLionel Sambuc   throw 0;
23f4a2713aSLionel Sambuc }
24f4a2713aSLionel Sambuc 
25f4a2713aSLionel Sambuc 
delegator(bool)26f4a2713aSLionel Sambuc delegator::delegator(bool)
27f4a2713aSLionel Sambuc {}
28f4a2713aSLionel Sambuc 
29*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define {{.*}} @_ZN9delegatorC2Ec
30f4a2713aSLionel Sambuc // CHECK: {{.*}} @_ZN9delegatorC2Eb
31f4a2713aSLionel Sambuc // CHECK: void @__cxa_throw
32f4a2713aSLionel Sambuc // CHECK: void @__clang_call_terminate
33f4a2713aSLionel Sambuc // CHECK: {{.*}} @_ZN9delegatorD2Ev
34*0a6a1f1dSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define {{.*}} @_ZN9delegatorC1Ec
36*0a6a1f1dSLionel Sambuc // CHECK: {{.*}} @_ZN9delegatorC1Eb
37*0a6a1f1dSLionel Sambuc // CHECK: void @__cxa_throw
38*0a6a1f1dSLionel Sambuc // CHECK: void @__clang_call_terminate
39*0a6a1f1dSLionel Sambuc // CHECK: {{.*}} @_ZN9delegatorD1Ev
delegator(char)40f4a2713aSLionel Sambuc delegator::delegator(char)
41f4a2713aSLionel Sambuc   : delegator(true) {
42f4a2713aSLionel Sambuc   throw 0;
43f4a2713aSLionel Sambuc }
44f4a2713aSLionel Sambuc 
45*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define {{.*}} @_ZN9delegatorC2Ei
46*0a6a1f1dSLionel Sambuc // CHECK: {{.*}} @_ZN9delegatorC2Ev
47f4a2713aSLionel Sambuc // CHECK-NOT: void @_ZSt9terminatev
48f4a2713aSLionel Sambuc // CHECK: ret
49f4a2713aSLionel Sambuc // CHECK-NOT: void @_ZSt9terminatev
50*0a6a1f1dSLionel Sambuc 
51*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define {{.*}} @_ZN9delegatorC1Ei
52*0a6a1f1dSLionel Sambuc // CHECK: {{.*}} @_ZN9delegatorC1Ev
53f4a2713aSLionel Sambuc // CHECK-NOT: void @_ZSt9terminatev
54f4a2713aSLionel Sambuc // CHECK: ret
55f4a2713aSLionel Sambuc // CHECK-NOT: void @_ZSt9terminatev
delegator(int)56f4a2713aSLionel Sambuc delegator::delegator(int)
57f4a2713aSLionel Sambuc   : delegator()
58f4a2713aSLionel Sambuc {}
59f4a2713aSLionel Sambuc 
60f4a2713aSLionel Sambuc namespace PR12890 {
61f4a2713aSLionel Sambuc   class X {
62f4a2713aSLionel Sambuc     int x;
63f4a2713aSLionel Sambuc     X() = default;
64f4a2713aSLionel Sambuc     X(int);
65f4a2713aSLionel Sambuc   };
X(int)66f4a2713aSLionel Sambuc   X::X(int) : X() {}
67f4a2713aSLionel Sambuc }
68f4a2713aSLionel Sambuc // CHECK: define {{.*}} @_ZN7PR128901XC1Ei(%"class.PR12890::X"* %this, i32)
69f4a2713aSLionel Sambuc // CHECK: call void @llvm.memset.p0i8.{{i32|i64}}(i8* {{.*}}, i8 0, {{i32|i64}} 4, i32 4, i1 false)
70f4a2713aSLionel Sambuc 
71f4a2713aSLionel Sambuc namespace PR14588 {
72f4a2713aSLionel Sambuc   void other();
73f4a2713aSLionel Sambuc 
74f4a2713aSLionel Sambuc   class Base {
75f4a2713aSLionel Sambuc   public:
Base()76f4a2713aSLionel Sambuc     Base() { squawk(); }
~Base()77f4a2713aSLionel Sambuc     virtual ~Base() {}
78f4a2713aSLionel Sambuc 
squawk()79f4a2713aSLionel Sambuc     virtual void squawk() { other(); }
80f4a2713aSLionel Sambuc   };
81f4a2713aSLionel Sambuc 
82f4a2713aSLionel Sambuc 
83f4a2713aSLionel Sambuc   class Foo : public virtual Base {
84f4a2713aSLionel Sambuc   public:
85f4a2713aSLionel Sambuc     Foo();
86f4a2713aSLionel Sambuc     Foo(const void * inVoid);
~Foo()87f4a2713aSLionel Sambuc     virtual ~Foo() {}
88f4a2713aSLionel Sambuc 
squawk()89f4a2713aSLionel Sambuc     virtual void squawk() { other(); }
90f4a2713aSLionel Sambuc   };
91f4a2713aSLionel Sambuc 
92f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN7PR145883FooC1Ev(%"class.PR14588::Foo"*
93f4a2713aSLionel Sambuc   // CHECK: call void @_ZN7PR145883FooC1EPKv(
94f4a2713aSLionel Sambuc   // CHECK: invoke void @_ZN7PR145885otherEv()
95f4a2713aSLionel Sambuc   // CHECK: call void @_ZN7PR145883FooD1Ev
96f4a2713aSLionel Sambuc   // CHECK: resume
97f4a2713aSLionel Sambuc 
Foo()98f4a2713aSLionel Sambuc   Foo::Foo() : Foo(__null) { other(); }
Foo(const void * inVoid)99f4a2713aSLionel Sambuc   Foo::Foo(const void *inVoid) {
100f4a2713aSLionel Sambuc     squawk();
101f4a2713aSLionel Sambuc   }
102f4a2713aSLionel Sambuc 
103f4a2713aSLionel Sambuc }
104