1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s 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 { 10 non_const_copy(non_const_copy&); 11 non_const_copy& operator = (non_const_copy&) &; 12 non_const_copy& operator = (non_const_copy&) &&; 13 non_const_copy() = default; // expected-note {{not viable}} 14 }; 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}} 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; 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' without a user-provided default constructor}} 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 { 39 bad_decls(volatile bad_decls&) = default; // expected-error {{may not be volatile}} 40 bad_decls&& operator = (bad_decls) = default; // expected-error {{lvalue reference}} expected-error {{must return 'bad_decls &'}} 41 bad_decls& operator = (volatile bad_decls&) = default; // expected-error {{may not be volatile}} 42 bad_decls& operator = (const bad_decls&) const = default; // expected-error {{may not have 'const', 'constexpr' or 'volatile' qualifiers}} 43 }; 44 45 struct DefaultDelete { 46 DefaultDelete() = default; // expected-note {{previous declaration is here}} 47 DefaultDelete() = delete; // expected-error {{constructor cannot be redeclared}} 48 49 ~DefaultDelete() = default; // expected-note {{previous declaration is here}} 50 ~DefaultDelete() = delete; // expected-error {{destructor cannot be redeclared}} 51 52 DefaultDelete &operator=(const DefaultDelete &) = default; // expected-note {{previous declaration is here}} 53 DefaultDelete &operator=(const DefaultDelete &) = delete; // expected-error {{class member cannot be redeclared}} 54 }; 55 56 struct DeleteDefault { 57 DeleteDefault() = delete; // expected-note {{previous definition is here}} 58 DeleteDefault() = default; // expected-error {{constructor cannot be redeclared}} 59 60 ~DeleteDefault() = delete; // expected-note {{previous definition is here}} 61 ~DeleteDefault() = default; // expected-error {{destructor cannot be redeclared}} 62 63 DeleteDefault &operator=(const DeleteDefault &) = delete; // expected-note {{previous definition is here}} 64 DeleteDefault &operator=(const DeleteDefault &) = default; // expected-error {{class member cannot be redeclared}} 65 }; 66 67 struct A {}; struct B {}; 68 69 struct except_spec_a { 70 virtual ~except_spec_a() throw(A); 71 except_spec_a() throw(A); 72 }; 73 struct except_spec_b { 74 virtual ~except_spec_b() throw(B); 75 except_spec_b() throw(B); 76 }; 77 78 struct except_spec_d_good : except_spec_a, except_spec_b { 79 ~except_spec_d_good(); 80 }; 81 except_spec_d_good::~except_spec_d_good() = default; 82 struct except_spec_d_good2 : except_spec_a, except_spec_b { 83 ~except_spec_d_good2() = default; 84 }; 85 struct except_spec_d_bad : except_spec_a, except_spec_b { 86 ~except_spec_d_bad() noexcept; 87 }; 88 // FIXME: This should error because this exception spec is not 89 // compatible with the implicit exception spec. 90 except_spec_d_bad::~except_spec_d_bad() noexcept = default; 91 92 // FIXME: This should error because this exception spec is not 93 // compatible with the implicit exception spec. 94 struct except_spec_d_mismatch : except_spec_a, except_spec_b { 95 except_spec_d_mismatch() throw(A) = default; 96 }; 97 struct except_spec_d_match : except_spec_a, except_spec_b { 98 except_spec_d_match() throw(A, B) = default; 99 }; 100 101 // gcc-compatibility: allow attributes on default definitions 102 // (but not normal definitions) 103 struct S { S(); }; 104 S::S() __attribute((pure)) = default; 105 106 using size_t = decltype(sizeof(0)); 107 void *operator new(size_t) = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}} 108 void operator delete(void *) noexcept = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}} 109