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