brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.6 KiB · 6ae146f Raw
220 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s2 3struct 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 9struct 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  int uninit_field;15};16non_const_copy::non_const_copy(non_const_copy&) = default; // expected-note {{not viable}}17non_const_copy& non_const_copy::operator = (non_const_copy&) & = default; // expected-note {{not viable}}18non_const_copy& non_const_copy::operator = (non_const_copy&) && = default; // expected-note {{not viable}}19 20void fn1 () {21  non_copiable nc;22  non_copiable nc2 = nc; // expected-error {{deleted constructor}}23  nc = nc; // expected-error {{deleted operator}}24 25  non_const_copy ncc;26  non_const_copy ncc2 = ncc;27  ncc = ncc2;28  const non_const_copy cncc{};29  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}}30  non_const_copy ncc3 = cncc; // expected-error {{no matching}}31  ncc = cncc; // expected-error {{no viable overloaded}}32};33 34struct no_fields { };35struct all_init {36  int a = 0;37  int b = 0;38};39struct some_init {40  int a = 0;41  int b;42  int c = 0;43};44struct some_init_mutable {45  int a = 0;46  mutable int b;47  int c = 0;48};49struct some_init_def {50  some_init_def() = default;51  int a = 0;52  int b;53  int c = 0;54};55struct some_init_ctor {56  some_init_ctor();57  int a = 0;58  int b;59  int c = 0;60};61struct sub_some_init : public some_init_def { };62struct sub_some_init_ctor : public some_init_def {63  sub_some_init_ctor();64};65struct sub_some_init_ctor2 : public some_init_ctor {66};67struct some_init_container {68  some_init_def sid;69};70struct some_init_container_ctor {71  some_init_container_ctor();72  some_init_def sid;73};74struct no_fields_container {75  no_fields nf;76};77struct param_pack_ctor {78  template <typename... T>79  param_pack_ctor(T...);80  int n;81};82struct param_pack_ctor_field {83  param_pack_ctor ndc;84};85struct multi_param_pack_ctor {86  template <typename... T, typename... U>87  multi_param_pack_ctor(T..., U..., int f = 0);88  int n;89};90struct ignored_template_ctor_and_def {91  template <class T> ignored_template_ctor_and_def(T* f = nullptr);92  ignored_template_ctor_and_def() = default;93  int field;94};95template<bool, typename = void> struct enable_if {};96template<typename T> struct enable_if<true, T> { typedef T type; };97struct multi_param_pack_and_defaulted {98  template <typename... T,99            typename enable_if<sizeof...(T) != 0>::type* = nullptr>100  multi_param_pack_and_defaulted(T...);101  multi_param_pack_and_defaulted() = default;102  int n;103};104 105void constobjs() {106  const no_fields nf; // ok107  const all_init ai; // ok108  const some_init si; // expected-error {{default initialization of an object of const type 'const some_init' without a user-provided default constructor}}109  const some_init_mutable sim; // ok110  const some_init_def sid; // expected-error {{default initialization of an object of const type 'const some_init_def' without a user-provided default constructor}}111  const some_init_ctor sic; // ok112  const sub_some_init ssi; // expected-error {{default initialization of an object of const type 'const sub_some_init' without a user-provided default constructor}}113  const sub_some_init_ctor ssic; // ok114  const sub_some_init_ctor2 ssic2; // ok115  const some_init_container sicon; // expected-error {{default initialization of an object of const type 'const some_init_container' without a user-provided default constructor}}116  const some_init_container_ctor siconc; // ok117  const no_fields_container nfc; // ok118  const param_pack_ctor ppc; // ok119  const param_pack_ctor_field ppcf; // ok120  const multi_param_pack_ctor mppc; // ok121  const multi_param_pack_and_defaulted mppad; // expected-error {{default initialization of an object of const type 'const multi_param_pack_and_defaulted' without a user-provided default constructor}}122  const ignored_template_ctor_and_def itcad; // expected-error {{default initialization of an object of const type 'const ignored_template_ctor_and_def' without a user-provided default constructor}}123 124}125 126struct non_const_derived : non_const_copy {127  non_const_derived(const non_const_derived&) = default; // expected-error {{requires it to be non-const}}128  non_const_derived& operator =(non_const_derived&) = default;129};130 131struct bad_decls {132  bad_decls(volatile bad_decls&) = default; // expected-error {{may not be volatile}}133  bad_decls&& operator = (bad_decls) = default; // expected-error {{lvalue reference}} expected-error {{must return 'bad_decls &'}}134  bad_decls& operator = (volatile bad_decls&) = default; // expected-error {{may not be volatile}}135  bad_decls& operator = (const bad_decls&) const = default; // expected-error {{may not have 'const', 'constexpr' or 'volatile' qualifiers}}136};137 138struct DefaultDelete {139  DefaultDelete() = default; // expected-note {{previous definition is here}}140  DefaultDelete() = delete; // expected-error {{constructor cannot be redeclared}}141 142  ~DefaultDelete() = default; // expected-note {{previous definition is here}}143  ~DefaultDelete() = delete; // expected-error {{destructor cannot be redeclared}}144 145  DefaultDelete &operator=(const DefaultDelete &) = default; // expected-note {{previous definition is here}}146  DefaultDelete &operator=(const DefaultDelete &) = delete; // expected-error {{class member cannot be redeclared}}147};148 149struct DeleteDefault {150  DeleteDefault() = delete; // expected-note {{previous definition is here}}151  DeleteDefault() = default; // expected-error {{constructor cannot be redeclared}}152 153  ~DeleteDefault() = delete; // expected-note {{previous definition is here}}154  ~DeleteDefault() = default; // expected-error {{destructor cannot be redeclared}}155 156  DeleteDefault &operator=(const DeleteDefault &) = delete; // expected-note {{previous definition is here}}157  DeleteDefault &operator=(const DeleteDefault &) = default; // expected-error {{class member cannot be redeclared}}158};159 160struct A {}; struct B {};161 162struct except_spec_a {163  virtual ~except_spec_a() throw(A);164  except_spec_a() throw(A);165};166struct except_spec_b {167  virtual ~except_spec_b() throw(B);168  except_spec_b() throw(B);169};170 171struct except_spec_d_good : except_spec_a, except_spec_b {172  ~except_spec_d_good();173};174except_spec_d_good::~except_spec_d_good() = default;175struct except_spec_d_good2 : except_spec_a, except_spec_b {176  ~except_spec_d_good2() = default;177};178struct except_spec_d_bad : except_spec_a, except_spec_b {179  ~except_spec_d_bad() noexcept;180};181// FIXME: This should error because this exception spec is not182// compatible with the implicit exception spec.183except_spec_d_bad::~except_spec_d_bad() noexcept = default;184 185// FIXME: This should error because this exception spec is not186// compatible with the implicit exception spec.187struct except_spec_d_mismatch : except_spec_a, except_spec_b {188  except_spec_d_mismatch() throw(A) = default;189};190struct except_spec_d_match : except_spec_a, except_spec_b {191  except_spec_d_match() throw(A, B) = default;192};193 194// gcc-compatibility: allow attributes on default definitions195// (but not normal definitions)196struct S { S(); };197S::S() __attribute((noreturn)) = default;198 199using size_t = decltype(sizeof(0));200void *operator new(size_t) = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}}201void operator delete(void *) noexcept = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}}202 203// FIXME: Diagnosing the call as "no matching function" due to substitution204// failure is not ideal.205template<typename T> void delete_template_too_late(); // expected-note {{previous}}206template<typename T> void delete_template_too_late() = delete; // expected-error {{must be first decl}} expected-note {{substitution failure}}207void use_template_deleted_too_late() { delete_template_too_late<int>(); } // expected-error {{no matching function}}208 209struct DeletedMemberTemplateTooLate {210  template<typename T> static void f(); // expected-note {{previous}}211};212template<typename T> void DeletedMemberTemplateTooLate::f() = delete; // expected-error {{must be first decl}} expected-note {{substitution failure}}213void use_member_template_deleted_too_late() { DeletedMemberTemplateTooLate::f<int>(); } // expected-error {{no matching function}}214 215namespace deleted_overrides_deleted {216  struct A { virtual void f() = delete; };217  template<typename T> struct B : A { virtual void f() = delete; };218  template struct B<int>;219}220