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