blob: b1078dc404b17a76d3eb4ff3ddb7c4e1ae3cae90 [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
Sean Huntbe631222011-05-17 20:44:43 +00002
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 {
Richard Smith3003e1d2012-05-15 04:39:51 +000010 non_const_copy(non_const_copy&);
11 non_const_copy& operator = (non_const_copy&) &;
12 non_const_copy& operator = (non_const_copy&) &&;
Sean Huntbe631222011-05-17 20:44:43 +000013 non_const_copy() = default; // expected-note {{not viable}}
14};
Richard Smith3003e1d2012-05-15 04:39:51 +000015non_const_copy::non_const_copy(non_const_copy&) = default; // expected-note {{not viable}}
16non_const_copy& non_const_copy::operator = (non_const_copy&) & = default; // expected-note {{not viable}}
17non_const_copy& non_const_copy::operator = (non_const_copy&) && = default; // expected-note {{not viable}}
Sean Huntbe631222011-05-17 20:44:43 +000018
19void 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;
Aaron Ballman51217812012-07-31 22:40:31 +000027 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}}
Sean Huntbe631222011-05-17 20:44:43 +000029 non_const_copy ncc3 = cncc; // expected-error {{no matching}}
30 ncc = cncc; // expected-error {{no viable overloaded}}
31};
32
33struct 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
38struct bad_decls {
Richard Smithac713512012-12-08 02:53:02 +000039 bad_decls(volatile bad_decls&) = default; // expected-error {{may not be volatile}}
Richard Smith3003e1d2012-05-15 04:39:51 +000040 bad_decls&& operator = (bad_decls) = default; // expected-error {{lvalue reference}} expected-error {{must return 'bad_decls &'}}
Richard Smithac713512012-12-08 02:53:02 +000041 bad_decls& operator = (volatile bad_decls&) = default; // expected-error {{may not be volatile}}
Richard Smith55dec862011-09-30 00:45:47 +000042 bad_decls& operator = (const bad_decls&) const = default; // expected-error {{may not have 'const', 'constexpr' or 'volatile' qualifiers}}
Sean Huntbe631222011-05-17 20:44:43 +000043};
44
45struct A {}; struct B {};
46
47struct except_spec_a {
48 virtual ~except_spec_a() throw(A);
49 except_spec_a() throw(A);
50};
51struct except_spec_b {
52 virtual ~except_spec_b() throw(B);
53 except_spec_b() throw(B);
54};
55
56struct except_spec_d_good : except_spec_a, except_spec_b {
57 ~except_spec_d_good();
58};
59except_spec_d_good::~except_spec_d_good() = default;
Richard Smithac713512012-12-08 02:53:02 +000060struct except_spec_d_good2 : except_spec_a, except_spec_b {
61 ~except_spec_d_good2() = default;
Sean Huntbe631222011-05-17 20:44:43 +000062};
Richard Smithac713512012-12-08 02:53:02 +000063struct 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.
68except_spec_d_bad::~except_spec_d_bad() noexcept = default;
Sean Huntbe631222011-05-17 20:44:43 +000069
Richard Smithac713512012-12-08 02:53:02 +000070// FIXME: This should error because this exception spec is not
71// compatible with the implicit exception spec.
Sean Huntbe631222011-05-17 20:44:43 +000072struct except_spec_d_mismatch : except_spec_a, except_spec_b {
73 except_spec_d_mismatch() throw(A) = default;
74};
75struct except_spec_d_match : except_spec_a, except_spec_b {
76 except_spec_d_match() throw(A, B) = default;
Aaron Ballman51217812012-07-31 22:40:31 +000077};
DeLesley Hutchinsc24a2332012-02-16 16:50:43 +000078
79// gcc-compatibility: allow attributes on default definitions
80// (but not normal definitions)
81struct S { S(); };
82S::S() __attribute((pure)) = default;