1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s 2f4a2713aSLionel Sambuc 3f4a2713aSLionel Sambuc struct non_copiable { 4f4a2713aSLionel Sambuc non_copiable(const non_copiable&) = delete; // expected-note {{marked deleted here}} 5f4a2713aSLionel Sambuc non_copiable& operator = (const non_copiable&) = delete; // expected-note {{explicitly deleted}} 6f4a2713aSLionel Sambuc non_copiable() = default; 7f4a2713aSLionel Sambuc }; 8f4a2713aSLionel Sambuc 9f4a2713aSLionel Sambuc struct non_const_copy { 10f4a2713aSLionel Sambuc non_const_copy(non_const_copy&); 11f4a2713aSLionel Sambuc non_const_copy& operator = (non_const_copy&) &; 12f4a2713aSLionel Sambuc non_const_copy& operator = (non_const_copy&) &&; 13f4a2713aSLionel Sambuc non_const_copy() = default; // expected-note {{not viable}} 14f4a2713aSLionel Sambuc }; 15f4a2713aSLionel Sambuc non_const_copy::non_const_copy(non_const_copy&) = default; // expected-note {{not viable}} 16f4a2713aSLionel Sambuc non_const_copy& non_const_copy::operator = (non_const_copy&) & = default; // expected-note {{not viable}} 17f4a2713aSLionel Sambuc non_const_copy& non_const_copy::operator = (non_const_copy&) && = default; // expected-note {{not viable}} 18f4a2713aSLionel Sambuc fn1()19f4a2713aSLionel Sambucvoid fn1 () { 20f4a2713aSLionel Sambuc non_copiable nc; 21f4a2713aSLionel Sambuc non_copiable nc2 = nc; // expected-error {{deleted constructor}} 22f4a2713aSLionel Sambuc nc = nc; // expected-error {{deleted operator}} 23f4a2713aSLionel Sambuc 24f4a2713aSLionel Sambuc non_const_copy ncc; 25f4a2713aSLionel Sambuc non_const_copy ncc2 = ncc; 26f4a2713aSLionel Sambuc ncc = ncc2; 27f4a2713aSLionel Sambuc const non_const_copy cncc{}; 28*0a6a1f1dSLionel Sambuc 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}} expected-note {{add an explicit initializer to initialize 'cncc1'}} 29f4a2713aSLionel Sambuc non_const_copy ncc3 = cncc; // expected-error {{no matching}} 30f4a2713aSLionel Sambuc ncc = cncc; // expected-error {{no viable overloaded}} 31f4a2713aSLionel Sambuc }; 32f4a2713aSLionel Sambuc 33f4a2713aSLionel Sambuc struct non_const_derived : non_const_copy { 34f4a2713aSLionel Sambuc non_const_derived(const non_const_derived&) = default; // expected-error {{requires it to be non-const}} 35f4a2713aSLionel Sambuc non_const_derived& operator =(non_const_derived&) = default; 36f4a2713aSLionel Sambuc }; 37f4a2713aSLionel Sambuc 38f4a2713aSLionel Sambuc struct bad_decls { 39f4a2713aSLionel Sambuc bad_decls(volatile bad_decls&) = default; // expected-error {{may not be volatile}} 40f4a2713aSLionel Sambuc bad_decls&& operator = (bad_decls) = default; // expected-error {{lvalue reference}} expected-error {{must return 'bad_decls &'}} 41f4a2713aSLionel Sambuc bad_decls& operator = (volatile bad_decls&) = default; // expected-error {{may not be volatile}} 42f4a2713aSLionel Sambuc bad_decls& operator = (const bad_decls&) const = default; // expected-error {{may not have 'const', 'constexpr' or 'volatile' qualifiers}} 43f4a2713aSLionel Sambuc }; 44f4a2713aSLionel Sambuc 45f4a2713aSLionel Sambuc struct A {}; struct B {}; 46f4a2713aSLionel Sambuc 47f4a2713aSLionel Sambuc struct except_spec_a { 48f4a2713aSLionel Sambuc virtual ~except_spec_a() throw(A); 49f4a2713aSLionel Sambuc except_spec_a() throw(A); 50f4a2713aSLionel Sambuc }; 51f4a2713aSLionel Sambuc struct except_spec_b { 52f4a2713aSLionel Sambuc virtual ~except_spec_b() throw(B); 53f4a2713aSLionel Sambuc except_spec_b() throw(B); 54f4a2713aSLionel Sambuc }; 55f4a2713aSLionel Sambuc 56f4a2713aSLionel Sambuc struct except_spec_d_good : except_spec_a, except_spec_b { 57f4a2713aSLionel Sambuc ~except_spec_d_good(); 58f4a2713aSLionel Sambuc }; 59f4a2713aSLionel Sambuc except_spec_d_good::~except_spec_d_good() = default; 60f4a2713aSLionel Sambuc struct except_spec_d_good2 : except_spec_a, except_spec_b { 61f4a2713aSLionel Sambuc ~except_spec_d_good2() = default; 62f4a2713aSLionel Sambuc }; 63f4a2713aSLionel Sambuc struct except_spec_d_bad : except_spec_a, except_spec_b { 64f4a2713aSLionel Sambuc ~except_spec_d_bad() noexcept; 65f4a2713aSLionel Sambuc }; 66f4a2713aSLionel Sambuc // FIXME: This should error because this exception spec is not 67f4a2713aSLionel Sambuc // compatible with the implicit exception spec. 68f4a2713aSLionel Sambuc except_spec_d_bad::~except_spec_d_bad() noexcept = default; 69f4a2713aSLionel Sambuc 70f4a2713aSLionel Sambuc // FIXME: This should error because this exception spec is not 71f4a2713aSLionel Sambuc // compatible with the implicit exception spec. 72f4a2713aSLionel Sambuc struct except_spec_d_mismatch : except_spec_a, except_spec_b { 73f4a2713aSLionel Sambuc except_spec_d_mismatch() throw(A) = default; 74f4a2713aSLionel Sambuc }; 75f4a2713aSLionel Sambuc struct except_spec_d_match : except_spec_a, except_spec_b { 76f4a2713aSLionel Sambuc except_spec_d_match() throw(A, B) = default; 77f4a2713aSLionel Sambuc }; 78f4a2713aSLionel Sambuc 79f4a2713aSLionel Sambuc // gcc-compatibility: allow attributes on default definitions 80f4a2713aSLionel Sambuc // (but not normal definitions) 81f4a2713aSLionel Sambuc struct S { S(); }; 82f4a2713aSLionel Sambuc S::S() __attribute((pure)) = default; 83*0a6a1f1dSLionel Sambuc 84*0a6a1f1dSLionel Sambuc using size_t = decltype(sizeof(0)); 85*0a6a1f1dSLionel Sambuc void *operator new(size_t) = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}} 86*0a6a1f1dSLionel Sambuc void operator delete(void *) noexcept = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}} 87