1// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -O3 -o - | FileCheck %s
2
3struct Empty { };
4
5struct A {
6  explicit A(unsigned a = 0xffffffff) : a(a) { }
7
8  unsigned a;
9};
10
11struct B : A, Empty {
12  B() : A(), Empty() { }
13};
14
15struct C : A, Empty {
16  C() : A(), Empty() { }
17  C(const C& other) : A(0x12345678), Empty(other) { }
18};
19
20struct D : A, Empty {
21  D& operator=(const D& other) {
22    a = 0x87654321;
23    Empty::operator=(other);
24
25    return *this;
26  }
27};
28
29#define CHECK(x) if (!(x)) return __LINE__
30
31// PR7012
32// CHECK: define i32 @_Z1fv()
33int f() {
34  B b1;
35
36  // Check that A::a is not overwritten by the Empty default constructor.
37  CHECK(b1.a == 0xffffffff);
38
39  C c1;
40  C c2(c1);
41
42  // Check that A::a has the value set in the C::C copy constructor.
43  CHECK(c2.a == 0x12345678);
44
45  D d1, d2;
46  d2 = d1;
47
48  // Check that A::as has the value set in the D copy assignment operator.
49  CHECK(d2.a == 0x87654321);
50
51  // Success!
52  // CHECK: ret i32 0
53  return 0;
54}
55
56namespace PR8796 {
57  struct FreeCell {
58  };
59  union ThingOrCell {
60    FreeCell t;
61    FreeCell cell;
62  };
63  struct Things {
64    ThingOrCell things;
65  };
66  Things x;
67}
68
69#ifdef HARNESS
70extern "C" void printf(const char *, ...);
71
72int main() {
73  int result = f();
74
75  if (result == 0)
76    printf("success!\n");
77  else
78    printf("test on line %d failed!\n", result);
79
80  return result;
81}
82#endif
83