1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++1y %s -DCXX1Y 3 4 // An aggregate is an array or a class... 5 struct Aggr { 6 private: 7 static const int n; 8 void f(); 9 protected: 10 struct Inner { int m; }; 11 public: 12 bool &br; // expected-note {{default constructor of 'Aggr' is implicitly deleted because field 'br' of reference type 'bool &' would not be initialized}} 13 }; 14 bool b; 15 Aggr ag = { b }; 16 17 // with no user-provided constructors, ... 18 struct NonAggr1a { // expected-note 2 {{candidate constructor}} 19 NonAggr1a(int, int); // expected-note {{candidate constructor}} 20 int k; 21 }; 22 NonAggr1a na1a = { 42 }; // expected-error {{no matching constructor for initialization of 'NonAggr1a'}} 23 24 struct NonAggr1b { 25 NonAggr1b(const NonAggr1b &); // expected-note {{candidate constructor}} 26 int k; 27 }; 28 NonAggr1b na1b = { 42 }; // expected-error {{no matching constructor for initialization of 'NonAggr1b'}} 29 30 // no brace-or-equal-initializers for non-static data members, ... 31 // Note, this bullet was removed in C++1y. 32 struct NonAggr2 { 33 int m = { 123 }; 34 }; 35 NonAggr2 na2 = { 42 }; 36 #ifndef CXX1Y 37 // expected-error@-2 {{no matching constructor for initialization of 'NonAggr2'}} 38 // expected-note@-6 3 {{candidate constructor}} 39 #endif 40 41 // no private... 42 struct NonAggr3 { // expected-note 3 {{candidate constructor}} 43 private: 44 int n; 45 }; 46 NonAggr3 na3 = { 42 }; // expected-error {{no matching constructor for initialization of 'NonAggr3'}} 47 48 // or protected non-static data members, ... 49 struct NonAggr4 { // expected-note 3 {{candidate constructor}} 50 protected: 51 int n; 52 }; 53 NonAggr4 na4 = { 42 }; // expected-error {{no matching constructor for initialization of 'NonAggr4'}} 54 55 // no base classes, ... 56 struct NonAggr5 : Aggr { // expected-note 3 {{candidate constructor}} 57 }; 58 NonAggr5 na5 = { b }; // expected-error {{no matching constructor for initialization of 'NonAggr5'}} 59 template<typename...BaseList> 60 struct MaybeAggr5a : BaseList... {}; // expected-note {{default constructor of 'MaybeAggr5a<Aggr>' is implicitly deleted because base class 'Aggr' has a deleted default constructor}} 61 MaybeAggr5a<> ma5a0 = {}; // ok 62 MaybeAggr5a<Aggr> ma5a1 = {}; // expected-error {{call to implicitly-deleted default constructor of 'MaybeAggr5a<Aggr>'}} 63 64 // and no virtual functions. 65 struct NonAggr6 { // expected-note 3 {{candidate constructor}} 66 virtual void f(); 67 int n; 68 }; 69 NonAggr6 na6 = { 42 }; // expected-error {{no matching constructor for initialization of 'NonAggr6'}} 70 71 struct DefaultedAggr { 72 int n; 73 74 DefaultedAggr() = default; 75 DefaultedAggr(const DefaultedAggr &) = default; 76 DefaultedAggr(DefaultedAggr &&) = default; 77 DefaultedAggr &operator=(const DefaultedAggr &) = default; 78 DefaultedAggr &operator=(DefaultedAggr &&) = default; 79 ~DefaultedAggr() = default; 80 }; 81 DefaultedAggr da = { 42 } ; 82