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