| 1 | // RUN: %clang_cc1 -std=c++11 -verify %s |
| 2 | |
| 3 | namespace std_example { |
| 4 | struct B1 { |
| 5 | B1(int, ...) {} |
| 6 | }; |
| 7 | |
| 8 | struct B2 { |
| 9 | B2(double) {} |
| 10 | }; |
| 11 | |
| 12 | int get(); |
| 13 | |
| 14 | struct D1 : B1 { // expected-note {{no default constructor}} |
| 15 | using B1::B1; // inherits B1(int, ...) |
| 16 | int x; |
| 17 | int y = get(); |
| 18 | }; |
| 19 | |
| 20 | void test() { |
| 21 | D1 d(2, 3, 4); // OK: B1 is initialized by calling B1(2, 3, 4), |
| 22 | // then d.x is default-initialized (no initialization is performed), |
| 23 | // then d.y is initialized by calling get() |
| 24 | D1 e; // expected-error {{implicitly-deleted}} |
| 25 | } |
| 26 | |
| 27 | struct D2 : B2 { |
| 28 | using B2::B2; |
| 29 | B1 b; // expected-note {{constructor inherited by 'D2' is implicitly deleted because field 'b' has no default constructor}} |
| 30 | }; |
| 31 | |
| 32 | D2 f(1.0); // expected-error {{constructor inherited by 'D2' from base class 'B2' is implicitly deleted}} |
| 33 | |
| 34 | struct W { |
| 35 | W(int); |
| 36 | }; |
| 37 | struct X : virtual W { |
| 38 | using W::W; |
| 39 | X() = delete; |
| 40 | }; |
| 41 | struct Y : X { |
| 42 | using X::X; |
| 43 | }; |
| 44 | struct Z : Y, virtual W { |
| 45 | using Y::Y; |
| 46 | }; |
| 47 | Z z(0); // OK: initialization of Y does not invoke default constructor of X |
| 48 | |
| 49 | template <class T> struct Log : T { |
| 50 | using T::T; // inherits all constructors from class T |
| 51 | ~Log() { /* ... */ } |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | namespace vbase { |
| 56 | struct V { |
| 57 | V(int); |
| 58 | }; |
| 59 | |
| 60 | struct A : virtual V { |
| 61 | A() = delete; // expected-note 2{{deleted here}} expected-note {{deleted}} |
| 62 | using V::V; |
| 63 | }; |
| 64 | struct B : virtual V { // expected-note {{no default constructor}} |
| 65 | B() = delete; // expected-note 2{{deleted here}} |
| 66 | B(int, int); |
| 67 | using V::V; |
| 68 | }; |
| 69 | struct C : B { // expected-note {{deleted default constructor}} |
| 70 | using B::B; |
| 71 | }; |
| 72 | struct D : A, C { // expected-note {{deleted default constructor}} expected-note {{deleted corresponding constructor}} |
| 73 | using A::A; |
| 74 | using C::C; |
| 75 | }; |
| 76 | |
| 77 | A a0; // expected-error {{deleted}} |
| 78 | A a1(0); |
| 79 | B b0; // expected-error {{deleted}} |
| 80 | B b1(0); |
| 81 | B b2(0, 0); |
| 82 | C c0; // expected-error {{deleted}} |
| 83 | C c1(0); |
| 84 | C c2(0, 0); // expected-error {{deleted}} |
| 85 | D d0; // expected-error {{deleted}} |
| 86 | D d1(0); |
| 87 | D d2(0, 0); // expected-error {{deleted}} |
| 88 | } |
| 89 | |
| 90 | namespace vbase_of_vbase { |
| 91 | struct V { V(int); }; |
| 92 | struct W : virtual V { using V::V; }; |
| 93 | struct X : virtual W, virtual V { using W::W; }; |
| 94 | X x(0); |
| 95 | } |
| 96 | |
| 97 | namespace constexpr_init_order { |
| 98 | struct Param; |
| 99 | struct A { |
| 100 | constexpr A(Param); |
| 101 | int a; |
| 102 | }; |
| 103 | |
| 104 | struct B : A { B(); using A::A; int b = 2; }; |
| 105 | extern const B b; |
| 106 | |
| 107 | struct Param { |
| 108 | constexpr Param(int c) : n(4 * b.a + b.b + c) {} |
| 109 | int n; |
| 110 | }; |
| 111 | |
| 112 | constexpr A::A(Param p) : a(p.n) {} |
| 113 | |
| 114 | constexpr B b(1); |
| 115 | constexpr B c(1); |
| 116 | static_assert(b.a == 1, "p should be initialized before B() is executed"); |
| 117 | static_assert(c.a == 7, "b not initialized properly"); |
| 118 | } |
| 119 | |
| 120 | namespace default_args { |
| 121 | // We work around a defect in P0136R1 where it would reject reasonable |
| 122 | // code like the following: |
| 123 | struct Base { |
| 124 | Base(int = 0); |
| 125 | }; |
| 126 | struct Derived : Base { |
| 127 | using Base::Base; |
| 128 | }; |
| 129 | Derived d; |
| 130 | // FIXME: Once a fix is standardized, implement it. |
| 131 | } |
| 132 | |