copy-constructor-synthesis.cpp revision a5728872c7702ddd09537c95bc3cbd20e1f2fb09
1// RUN: %clang_cc1 -triple x86_64-apple-darwin -S %s -o %t-64.s 2// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s 3// RUN: %clang_cc1 -triple i386-apple-darwin -S %s -o %t-32.s 4// RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s 5 6extern "C" int printf(...); 7 8int init = 100; 9 10struct M { 11 int iM; 12 M() : iM(init++) {} 13}; 14 15struct N { 16 int iN; 17 N() : iN(200) {} 18 N(N const & arg){this->iN = arg.iN; } 19}; 20 21struct P { 22 int iP; 23 P() : iP(init++) {} 24}; 25 26 27struct X : M, N, P { // ... 28 X() : f1(1.0), d1(2.0), i1(3), name("HELLO"), bf1(0xff), bf2(0xabcd), 29 au_i1(1234), au1_4("MASKED") {} 30 P p0; 31 void pr() { 32 printf("iM = %d iN = %d, m1.iM = %d\n", iM, iN, m1.iM); 33 printf("im = %d p0.iP = %d, p1.iP = %d\n", iP, p0.iP, p1.iP); 34 printf("f1 = %f d1 = %f i1 = %d name(%s) \n", f1, d1, i1, name); 35 printf("bf1 = %x bf2 = %x\n", bf1, bf2); 36 printf("au_i2 = %d\n", au_i2); 37 printf("au1_1 = %s\n", au1_1); 38 } 39 M m1; 40 P p1; 41 float f1; 42 double d1; 43 int i1; 44 const char *name; 45 unsigned bf1 : 8; 46 unsigned bf2 : 16; 47 int arr[2]; 48 _Complex float complex; 49 50 union { 51 int au_i1; 52 int au_i2; 53 }; 54 union { 55 const char * au1_1; 56 float au1_2; 57 int au1_3; 58 const char * au1_4; 59 }; 60}; 61 62static int ix = 1; 63// class with user-defined copy constructor. 64struct S { 65 S() : iS(ix++) { } 66 S(const S& arg) { *this = arg; } 67 int iS; 68}; 69 70// class with trivial copy constructor. 71struct I { 72 I() : iI(ix++) { } 73 int iI; 74}; 75 76struct XM { 77 XM() { } 78 double dXM; 79 S ARR_S[3][4][2]; 80 void pr() { 81 for (unsigned i = 0; i < 3; i++) 82 for (unsigned j = 0; j < 4; j++) 83 for (unsigned k = 0; k < 2; k++) 84 printf("ARR_S[%d][%d][%d] = %d\n", i,j,k, ARR_S[i][j][k].iS); 85 for (unsigned i = 0; i < 3; i++) 86 for (unsigned k = 0; k < 2; k++) 87 printf("ARR_I[%d][%d] = %d\n", i,k, ARR_I[i][k].iI); 88 } 89 I ARR_I[3][2]; 90}; 91 92int main() { 93 X a; 94 X b(a); 95 b.pr(); 96 X x; 97 X c(x); 98 c.pr(); 99 100 XM m0; 101 XM m1 = m0; 102 m1.pr(); 103} 104 105struct A { 106}; 107 108struct B : A { 109 A &a; 110}; 111 112void f(const B &b1) { 113 B b2(b1); 114} 115 116// CHECK-LP64: .globl __ZN1XC1ERKS_ 117// CHECK-LP64: .weak_definition __ZN1XC1ERKS_ 118// CHECK-LP64: __ZN1XC1ERKS_: 119 120// CHECK-LP32: .globl __ZN1XC1ERKS_ 121// CHECK-LP32: .weak_definition __ZN1XC1ERKS_ 122// CHECK-LP32: __ZN1XC1ERKS_: 123