Home | History | Annotate | Download | only in SemaCXX
      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' requires 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 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;
     60 struct except_spec_d_good2 : except_spec_a, except_spec_b {
     61   ~except_spec_d_good2() = default;
     62 };
     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;
     69 
     70 // FIXME: This should error because this exception spec is not
     71 // compatible with the implicit exception spec.
     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;
     77 };
     78 
     79 // gcc-compatibility: allow attributes on default definitions
     80 // (but not normal definitions)
     81 struct S { S(); };
     82 S::S() __attribute((pure)) = default;
     83 
     84 using size_t = decltype(sizeof(0));
     85 void *operator new(size_t) = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}}
     86 void operator delete(void *) noexcept = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}}
     87