blob: 595d428806f7f7745ca1b472c57e42cd282b7043 [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
Sean Hunt1f2f3842011-05-17 00:19:05 +00002
3void fn() = default; // expected-error {{only special member}}
4struct foo {
5 void fn() = default; // expected-error {{only special member}}
6
7 foo() = default;
8 foo(const foo&) = default;
Richard Smith3003e1d2012-05-15 04:39:51 +00009 foo(foo&&) = default;
Sean Hunt1f2f3842011-05-17 00:19:05 +000010 foo& operator = (const foo&) = default;
Richard Smith3003e1d2012-05-15 04:39:51 +000011 foo& operator = (foo&&) = default;
Sean Hunt1f2f3842011-05-17 00:19:05 +000012 ~foo() = default;
13};
14
15struct bar {
16 bar();
17 bar(const bar&);
Richard Smith3003e1d2012-05-15 04:39:51 +000018 bar(bar&&);
Sean Hunt1f2f3842011-05-17 00:19:05 +000019 bar& operator = (const bar&);
Richard Smith3003e1d2012-05-15 04:39:51 +000020 bar& operator = (bar&&);
Sean Hunt1f2f3842011-05-17 00:19:05 +000021 ~bar();
22};
23
24bar::bar() = default;
25bar::bar(const bar&) = default;
Richard Smith3003e1d2012-05-15 04:39:51 +000026bar::bar(bar&&) = default;
Sean Hunt1f2f3842011-05-17 00:19:05 +000027bar& bar::operator = (const bar&) = default;
Richard Smith3003e1d2012-05-15 04:39:51 +000028bar& bar::operator = (bar&&) = default;
Sean Hunt1f2f3842011-05-17 00:19:05 +000029bar::~bar() = default;
30
Richard Smitheb273b72012-02-14 02:33:50 +000031static_assert(__is_trivial(foo), "foo should be trivial");
Sean Hunt1f2f3842011-05-17 00:19:05 +000032
33static_assert(!__has_trivial_destructor(bar), "bar's destructor isn't trivial");
34static_assert(!__has_trivial_constructor(bar),
35 "bar's default constructor isn't trivial");
36static_assert(!__has_trivial_copy(bar), "bar has no trivial copy");
37static_assert(!__has_trivial_assign(bar), "bar has no trivial assign");
38
39void tester() {
40 foo f, g(f);
41 bar b, c(b);
42 f = g;
43 b = c;
44}
45
Richard Smitheb273b72012-02-14 02:33:50 +000046template<typename T> struct S : T {
47 constexpr S() = default;
48 constexpr S(const S&) = default;
49 constexpr S(S&&) = default;
50};
51struct lit { constexpr lit() {} };
52S<lit> s_lit; // ok
53S<bar> s_bar; // ok
Richard Smithf4fe8432012-06-08 01:30:54 +000054
55struct Friends {
56 friend S<bar>::S();
57 friend S<bar>::S(const S&);
58 friend S<bar>::S(S&&);
59};