Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %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; |
| 12 | }; |
| 13 | bool b; |
| 14 | Aggr ag = { b }; |
| 15 | |
| 16 | // with no user-provided constructors, ... |
| 17 | struct NonAggr1a { |
| 18 | NonAggr1a(int, int); |
| 19 | int k; |
| 20 | }; |
| 21 | // In C++03, this is {{non-aggregate type 'NonAggr1a'}}. |
| 22 | // In C++0x, 'user-provided' is only defined for special member functions, so |
| 23 | // this type is considered to be an aggregate. This is probably a langauge |
| 24 | // defect. |
| 25 | NonAggr1a na1a = { 42 }; |
| 26 | |
| 27 | struct NonAggr1b { |
| 28 | NonAggr1b(const NonAggr1b &); |
| 29 | int k; |
| 30 | }; |
| 31 | NonAggr1b na1b = { 42 }; // expected-error {{non-aggregate type 'NonAggr1b'}} |
| 32 | |
| 33 | // no brace-or-equal-initializers for non-static data members, ... |
| 34 | struct NonAggr2 { |
| 35 | int m = { 123 }; |
| 36 | }; |
| 37 | NonAggr2 na2 = { 42 }; // expected-error {{non-aggregate type 'NonAggr2'}} |
| 38 | |
| 39 | // no private... |
| 40 | struct NonAggr3 { |
| 41 | private: |
| 42 | int n; |
| 43 | }; |
| 44 | NonAggr3 na3 = { 42 }; // expected-error {{non-aggregate type 'NonAggr3'}} |
| 45 | |
| 46 | // or protected non-static data members, ... |
| 47 | struct NonAggr4 { |
| 48 | protected: |
| 49 | int n; |
| 50 | }; |
| 51 | NonAggr4 na4 = { 42 }; // expected-error {{non-aggregate type 'NonAggr4'}} |
| 52 | |
| 53 | // no base classes, ... |
| 54 | struct NonAggr5 : Aggr { |
| 55 | }; |
| 56 | NonAggr5 na5 = { b }; // expected-error {{non-aggregate type 'NonAggr5'}} |
| 57 | |
| 58 | // and no virtual functions. |
| 59 | struct NonAggr6 { |
| 60 | virtual void f(); |
| 61 | int n; |
| 62 | }; |
| 63 | NonAggr6 na6 = { 42 }; // expected-error {{non-aggregate type 'NonAggr6'}} |