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 | be63122 | 2011-05-17 20:44:43 +0000 | [diff] [blame] | 2 | |
| 3 | struct non_copiable { |
| 4 | non_copiable(const non_copiable&) = delete; // expected-note {{marked deleted here}} |
| 5 | non_copiable& operator = (const non_copiable&) = delete; // expected-note {{explicitly deleted}} |
| 6 | non_copiable() = default; |
| 7 | }; |
| 8 | |
| 9 | struct non_const_copy { |
Richard Smith | 3003e1d | 2012-05-15 04:39:51 +0000 | [diff] [blame] | 10 | non_const_copy(non_const_copy&); |
| 11 | non_const_copy& operator = (non_const_copy&) &; |
| 12 | non_const_copy& operator = (non_const_copy&) &&; |
Sean Hunt | be63122 | 2011-05-17 20:44:43 +0000 | [diff] [blame] | 13 | non_const_copy() = default; // expected-note {{not viable}} |
| 14 | }; |
Richard Smith | 3003e1d | 2012-05-15 04:39:51 +0000 | [diff] [blame] | 15 | non_const_copy::non_const_copy(non_const_copy&) = default; // expected-note {{not viable}} |
| 16 | non_const_copy& non_const_copy::operator = (non_const_copy&) & = default; // expected-note {{not viable}} |
| 17 | non_const_copy& non_const_copy::operator = (non_const_copy&) && = default; // expected-note {{not viable}} |
Sean Hunt | be63122 | 2011-05-17 20:44:43 +0000 | [diff] [blame] | 18 | |
| 19 | void fn1 () { |
| 20 | non_copiable nc; |
| 21 | non_copiable nc2 = nc; // expected-error {{deleted constructor}} |
| 22 | nc = nc; // expected-error {{deleted operator}} |
| 23 | |
| 24 | non_const_copy ncc; |
| 25 | non_const_copy ncc2 = ncc; |
| 26 | ncc = ncc2; |
Aaron Ballman | 5121781 | 2012-07-31 22:40:31 +0000 | [diff] [blame] | 27 | const non_const_copy cncc{}; |
| 28 | const non_const_copy cncc1; // expected-error {{default initialization of an object of const type 'const non_const_copy' requires a user-provided default constructor}} |
Sean Hunt | be63122 | 2011-05-17 20:44:43 +0000 | [diff] [blame] | 29 | non_const_copy ncc3 = cncc; // expected-error {{no matching}} |
| 30 | ncc = cncc; // expected-error {{no viable overloaded}} |
| 31 | }; |
| 32 | |
| 33 | struct non_const_derived : non_const_copy { |
| 34 | non_const_derived(const non_const_derived&) = default; // expected-error {{requires it to be non-const}} |
| 35 | non_const_derived& operator =(non_const_derived&) = default; |
| 36 | }; |
| 37 | |
| 38 | struct bad_decls { |
Richard Smith | ac71351 | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 39 | bad_decls(volatile bad_decls&) = default; // expected-error {{may not be volatile}} |
Richard Smith | 3003e1d | 2012-05-15 04:39:51 +0000 | [diff] [blame] | 40 | bad_decls&& operator = (bad_decls) = default; // expected-error {{lvalue reference}} expected-error {{must return 'bad_decls &'}} |
Richard Smith | ac71351 | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 41 | bad_decls& operator = (volatile bad_decls&) = default; // expected-error {{may not be volatile}} |
Richard Smith | 55dec86 | 2011-09-30 00:45:47 +0000 | [diff] [blame] | 42 | bad_decls& operator = (const bad_decls&) const = default; // expected-error {{may not have 'const', 'constexpr' or 'volatile' qualifiers}} |
Sean Hunt | be63122 | 2011-05-17 20:44:43 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | struct A {}; struct B {}; |
| 46 | |
| 47 | struct except_spec_a { |
| 48 | virtual ~except_spec_a() throw(A); |
| 49 | except_spec_a() throw(A); |
| 50 | }; |
| 51 | struct except_spec_b { |
| 52 | virtual ~except_spec_b() throw(B); |
| 53 | except_spec_b() throw(B); |
| 54 | }; |
| 55 | |
| 56 | struct except_spec_d_good : except_spec_a, except_spec_b { |
| 57 | ~except_spec_d_good(); |
| 58 | }; |
| 59 | except_spec_d_good::~except_spec_d_good() = default; |
Richard Smith | ac71351 | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 60 | struct except_spec_d_good2 : except_spec_a, except_spec_b { |
| 61 | ~except_spec_d_good2() = default; |
Sean Hunt | be63122 | 2011-05-17 20:44:43 +0000 | [diff] [blame] | 62 | }; |
Richard Smith | ac71351 | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 63 | struct except_spec_d_bad : except_spec_a, except_spec_b { |
| 64 | ~except_spec_d_bad() noexcept; |
| 65 | }; |
| 66 | // FIXME: This should error because this exception spec is not |
| 67 | // compatible with the implicit exception spec. |
| 68 | except_spec_d_bad::~except_spec_d_bad() noexcept = default; |
Sean Hunt | be63122 | 2011-05-17 20:44:43 +0000 | [diff] [blame] | 69 | |
Richard Smith | ac71351 | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 70 | // FIXME: This should error because this exception spec is not |
| 71 | // compatible with the implicit exception spec. |
Sean Hunt | be63122 | 2011-05-17 20:44:43 +0000 | [diff] [blame] | 72 | struct except_spec_d_mismatch : except_spec_a, except_spec_b { |
| 73 | except_spec_d_mismatch() throw(A) = default; |
| 74 | }; |
| 75 | struct except_spec_d_match : except_spec_a, except_spec_b { |
| 76 | except_spec_d_match() throw(A, B) = default; |
Aaron Ballman | 5121781 | 2012-07-31 22:40:31 +0000 | [diff] [blame] | 77 | }; |
DeLesley Hutchins | c24a233 | 2012-02-16 16:50:43 +0000 | [diff] [blame] | 78 | |
| 79 | // gcc-compatibility: allow attributes on default definitions |
| 80 | // (but not normal definitions) |
| 81 | struct S { S(); }; |
| 82 | S::S() __attribute((pure)) = default; |