1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s 3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s 4 5 // Verify that using an initializer list for a non-aggregate looks for 6 // constructors.. 7 struct NonAggr1 { // expected-note 2 {{candidate constructor}} 8 NonAggr1(int, int) { } // expected-note {{candidate constructor}} 9 10 int m; 11 }; 12 13 struct Base { }; 14 struct NonAggr2 : public Base { // expected-note 0-3 {{candidate constructor}} 15 int m; 16 }; 17 18 class NonAggr3 { // expected-note 3 {{candidate constructor}} 19 int m; 20 }; 21 22 struct NonAggr4 { // expected-note 3 {{candidate constructor}} 23 int m; 24 virtual void f(); 25 }; 26 27 NonAggr1 na1 = { 17 }; // expected-error{{no matching constructor for initialization of 'NonAggr1'}} 28 NonAggr2 na2 = { 17 }; 29 NonAggr3 na3 = { 17 }; // expected-error{{no matching constructor for initialization of 'NonAggr3'}} 30 NonAggr4 na4 = { 17 }; // expected-error{{no matching constructor for initialization of 'NonAggr4'}} 31 #if __cplusplus <= 201402L 32 // expected-error@-4{{no matching constructor for initialization of 'NonAggr2'}} 33 #else 34 // expected-error@-6{{requires explicit braces}} 35 NonAggr2 na2b = { {}, 17 }; // ok 36 #endif 37 38 // PR5817 39 typedef int type[][2]; 40 const type foo = {0}; 41 42 // Vector initialization. 43 typedef short __v4hi __attribute__ ((__vector_size__ (8))); 44 __v4hi v1 = { (void *)1, 2, 3 }; // expected-error {{cannot initialize a vector element of type 'short' with an rvalue of type 'void *'}} 45 46 // Array initialization. 47 int a[] = { (void *)1 }; // expected-error {{cannot initialize an array element of type 'int' with an rvalue of type 'void *'}} 48 49 // Struct initialization. 50 struct S { int a; } s = { (void *)1 }; // expected-error {{cannot initialize a member subobject of type 'int' with an rvalue of type 'void *'}} 51 52 // Check that we're copy-initializing the structs. 53 struct A { 54 A(); 55 A(int); 56 ~A(); 57 58 A(const A&) = delete; // expected-note 0-2{{'A' has been explicitly marked deleted here}} 59 }; 60 61 struct B { 62 A a; 63 }; 64 65 struct C { 66 const A& a; 67 }; 68 69 void f() { 70 A as1[1] = { }; 71 A as2[1] = { 1 }; 72 #if __cplusplus <= 201402L 73 // expected-error@-2 {{copying array element of type 'A' invokes deleted constructor}} 74 #endif 75 76 B b1 = { }; 77 B b2 = { 1 }; 78 #if __cplusplus <= 201402L 79 // expected-error@-2 {{copying member subobject of type 'A' invokes deleted constructor}} 80 #endif 81 82 C c1 = { 1 }; 83 } 84 85 class Agg { 86 public: 87 int i, j; 88 }; 89 90 class AggAgg { 91 public: 92 Agg agg1; 93 Agg agg2; 94 }; 95 96 AggAgg aggagg = { 1, 2, 3, 4 }; 97 98 namespace diff_cpp14_dcl_init_aggr_example { 99 struct derived; 100 struct base { 101 friend struct derived; 102 private: 103 base(); 104 }; 105 struct derived : base {}; 106 107 derived d1{}; 108 #if __cplusplus > 201402L 109 // expected-error@-2 {{private}} 110 // expected-note@-7 {{here}} 111 #endif 112 derived d2; 113 } 114 115 namespace ProtectedBaseCtor { 116 // FIXME: It's unclear whether f() and g() should be valid in C++1z. What is 117 // the object expression in a constructor call -- the base class subobject or 118 // the complete object? 119 struct A { 120 protected: 121 A(); 122 }; 123 124 struct B : public A { 125 friend B f(); 126 friend B g(); 127 friend B h(); 128 }; 129 130 B f() { return {}; } 131 #if __cplusplus > 201402L 132 // expected-error@-2 {{protected default constructor}} 133 // expected-note@-12 {{here}} 134 #endif 135 136 B g() { return {{}}; } 137 #if __cplusplus <= 201402L 138 // expected-error@-2 {{no matching constructor}} 139 // expected-note@-15 3{{candidate}} 140 #else 141 // expected-error@-5 {{protected default constructor}} 142 // expected-note@-21 {{here}} 143 #endif 144 145 B h() { return {A{}}; } 146 #if __cplusplus <= 201402L 147 // expected-error@-2 {{no matching constructor}} 148 // expected-note@-24 3{{candidate}} 149 #endif 150 // expected-error@-5 {{protected constructor}} 151 // expected-note@-30 {{here}} 152 } 153