Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s |
Sean Hunt | 1f2f384 | 2011-05-17 00:19:05 +0000 | [diff] [blame] | 2 | |
| 3 | void fn() = default; // expected-error {{only special member}} |
| 4 | struct foo { |
| 5 | void fn() = default; // expected-error {{only special member}} |
| 6 | |
| 7 | foo() = default; |
| 8 | foo(const foo&) = default; |
| 9 | foo(foo&) = default; |
| 10 | foo& operator = (const foo&) = default; |
| 11 | foo& operator = (foo&) = default; |
| 12 | ~foo() = default; |
| 13 | }; |
| 14 | |
| 15 | struct bar { |
| 16 | bar(); |
| 17 | bar(const bar&); |
| 18 | bar(bar&); |
| 19 | bar& operator = (const bar&); |
| 20 | bar& operator = (bar&); |
| 21 | ~bar(); |
| 22 | }; |
| 23 | |
| 24 | bar::bar() = default; |
| 25 | bar::bar(const bar&) = default; |
| 26 | bar::bar(bar&) = default; |
| 27 | bar& bar::operator = (const bar&) = default; |
| 28 | bar& bar::operator = (bar&) = default; |
| 29 | bar::~bar() = default; |
| 30 | |
Richard Smith | eb273b7 | 2012-02-14 02:33:50 +0000 | [diff] [blame] | 31 | static_assert(__is_trivial(foo), "foo should be trivial"); |
Sean Hunt | 1f2f384 | 2011-05-17 00:19:05 +0000 | [diff] [blame] | 32 | |
| 33 | static_assert(!__has_trivial_destructor(bar), "bar's destructor isn't trivial"); |
| 34 | static_assert(!__has_trivial_constructor(bar), |
| 35 | "bar's default constructor isn't trivial"); |
| 36 | static_assert(!__has_trivial_copy(bar), "bar has no trivial copy"); |
| 37 | static_assert(!__has_trivial_assign(bar), "bar has no trivial assign"); |
| 38 | |
| 39 | void tester() { |
| 40 | foo f, g(f); |
| 41 | bar b, c(b); |
| 42 | f = g; |
| 43 | b = c; |
| 44 | } |
| 45 | |
Richard Smith | eb273b7 | 2012-02-14 02:33:50 +0000 | [diff] [blame] | 46 | template<typename T> struct S : T { |
| 47 | constexpr S() = default; |
| 48 | constexpr S(const S&) = default; |
| 49 | constexpr S(S&&) = default; |
| 50 | }; |
| 51 | struct lit { constexpr lit() {} }; |
| 52 | S<lit> s_lit; // ok |
| 53 | S<bar> s_bar; // ok |