Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | |
| 3 | // FIXME: Very incomplete! |
| 4 | |
| 5 | // If a program calls for the default initialization of an object of a |
| 6 | // const-qualified type T, T shall be a class type with a |
| 7 | // user-provided default constructor. |
Douglas Gregor | 516a6bc | 2010-03-08 02:45:10 +0000 | [diff] [blame] | 8 | struct MakeNonPOD { MakeNonPOD(); }; |
| 9 | struct NoUserDefault : public MakeNonPOD { }; |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 10 | struct HasUserDefault { HasUserDefault(); }; |
| 11 | |
| 12 | void test_const_default_init() { |
Chris Lattner | 0c42bb6 | 2010-09-05 00:17:29 +0000 | [diff] [blame] | 13 | const NoUserDefault x1; // expected-error{{default initialization of an object of const type 'const NoUserDefault' requires a user-provided default constructor}} |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 14 | const HasUserDefault x2; |
Chris Lattner | 58f9e13 | 2010-09-05 00:04:01 +0000 | [diff] [blame] | 15 | const int x3; // expected-error{{default initialization of an object of const type 'const int'}} |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 16 | } |
Douglas Gregor | 4337dc7 | 2011-05-21 17:52:48 +0000 | [diff] [blame] | 17 | |
| 18 | // rdar://8501008 |
| 19 | struct s0 {}; |
| 20 | struct s1 { static const s0 foo; }; |
| 21 | const struct s0 s1::foo; // expected-error{{default initialization of an object of const type 'const struct s0' requires a user-provided default constructor}} |
| 22 | |
| 23 | template<typename T> |
| 24 | struct s2 { |
| 25 | static const s0 foo; |
| 26 | }; |
| 27 | |
| 28 | template<> const struct s0 s2<int>::foo; // okay |