[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / SemaCXX / cxx0x-cursory-default-delete.cpp
blob9d68a0e5d358f675b96c6638363dce8facaf1369
1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
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 };
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 int uninit_field;
16 non_const_copy::non_const_copy(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 non_const_copy& non_const_copy::operator = (non_const_copy&) && = default; // expected-note {{not viable}}
20 void fn1 () {
21 non_copiable nc;
22 non_copiable nc2 = nc; // expected-error {{deleted constructor}}
23 nc = nc; // expected-error {{deleted operator}}
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}}
34 struct no_fields { };
35 struct all_init {
36 int a = 0;
37 int b = 0;
39 struct some_init {
40 int a = 0;
41 int b;
42 int c = 0;
44 struct some_init_mutable {
45 int a = 0;
46 mutable int b;
47 int c = 0;
49 struct some_init_def {
50 some_init_def() = default;
51 int a = 0;
52 int b;
53 int c = 0;
55 struct some_init_ctor {
56 some_init_ctor();
57 int a = 0;
58 int b;
59 int c = 0;
61 struct sub_some_init : public some_init_def { };
62 struct sub_some_init_ctor : public some_init_def {
63 sub_some_init_ctor();
65 struct sub_some_init_ctor2 : public some_init_ctor {
67 struct some_init_container {
68 some_init_def sid;
70 struct some_init_container_ctor {
71 some_init_container_ctor();
72 some_init_def sid;
74 struct no_fields_container {
75 no_fields nf;
77 struct param_pack_ctor {
78 template <typename... T>
79 param_pack_ctor(T...);
80 int n;
82 struct param_pack_ctor_field {
83 param_pack_ctor ndc;
85 struct multi_param_pack_ctor {
86 template <typename... T, typename... U>
87 multi_param_pack_ctor(T..., U..., int f = 0);
88 int n;
90 struct 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;
95 template<bool, typename = void> struct enable_if {};
96 template<typename T> struct enable_if<true, T> { typedef T type; };
97 struct 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;
105 void constobjs() {
106 const no_fields nf; // ok
107 const all_init ai; // ok
108 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; // ok
110 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; // ok
112 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; // ok
114 const sub_some_init_ctor2 ssic2; // ok
115 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; // ok
117 const no_fields_container nfc; // ok
118 const param_pack_ctor ppc; // ok
119 const param_pack_ctor_field ppcf; // ok
120 const multi_param_pack_ctor mppc; // ok
121 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}}
126 struct 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;
131 struct 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}}
138 struct DefaultDelete {
139 DefaultDelete() = default; // expected-note {{previous definition is here}}
140 DefaultDelete() = delete; // expected-error {{constructor cannot be redeclared}}
142 ~DefaultDelete() = default; // expected-note {{previous definition is here}}
143 ~DefaultDelete() = delete; // expected-error {{destructor cannot be redeclared}}
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}}
149 struct DeleteDefault {
150 DeleteDefault() = delete; // expected-note {{previous definition is here}}
151 DeleteDefault() = default; // expected-error {{constructor cannot be redeclared}}
153 ~DeleteDefault() = delete; // expected-note {{previous definition is here}}
154 ~DeleteDefault() = default; // expected-error {{destructor cannot be redeclared}}
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}}
160 struct A {}; struct B {};
162 struct except_spec_a {
163 virtual ~except_spec_a() throw(A);
164 except_spec_a() throw(A);
166 struct except_spec_b {
167 virtual ~except_spec_b() throw(B);
168 except_spec_b() throw(B);
171 struct except_spec_d_good : except_spec_a, except_spec_b {
172 ~except_spec_d_good();
174 except_spec_d_good::~except_spec_d_good() = default;
175 struct except_spec_d_good2 : except_spec_a, except_spec_b {
176 ~except_spec_d_good2() = default;
178 struct except_spec_d_bad : except_spec_a, except_spec_b {
179 ~except_spec_d_bad() noexcept;
181 // FIXME: This should error because this exception spec is not
182 // compatible with the implicit exception spec.
183 except_spec_d_bad::~except_spec_d_bad() noexcept = default;
185 // FIXME: This should error because this exception spec is not
186 // compatible with the implicit exception spec.
187 struct except_spec_d_mismatch : except_spec_a, except_spec_b {
188 except_spec_d_mismatch() throw(A) = default;
190 struct except_spec_d_match : except_spec_a, except_spec_b {
191 except_spec_d_match() throw(A, B) = default;
194 // gcc-compatibility: allow attributes on default definitions
195 // (but not normal definitions)
196 struct S { S(); };
197 S::S() __attribute((pure)) = default;
199 using size_t = decltype(sizeof(0));
200 void *operator new(size_t) = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}}
201 void operator delete(void *) noexcept = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}}
203 // FIXME: Diagnosing the call as "no matching function" due to substitution
204 // failure is not ideal.
205 template<typename T> void delete_template_too_late(); // expected-note {{previous}}
206 template<typename T> void delete_template_too_late() = delete; // expected-error {{must be first decl}} expected-note {{substitution failure}}
207 void use_template_deleted_too_late() { delete_template_too_late<int>(); } // expected-error {{no matching function}}
209 struct DeletedMemberTemplateTooLate {
210 template<typename T> static void f(); // expected-note {{previous}}
212 template<typename T> void DeletedMemberTemplateTooLate::f() = delete; // expected-error {{must be first decl}} expected-note {{substitution failure}}
213 void use_member_template_deleted_too_late() { DeletedMemberTemplateTooLate::f<int>(); } // expected-error {{no matching function}}
215 namespace 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>;