blob: f00297332a54625b94033fddf355159cd4f57bf8 [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;
27 const non_const_copy cncc;
28 non_const_copy ncc3 = cncc; // expected-error {{no matching}}
29 ncc = cncc; // expected-error {{no viable overloaded}}
30};
31
32struct non_const_derived : non_const_copy {
33 non_const_derived(const non_const_derived&) = default; // expected-error {{requires it to be non-const}}
34 non_const_derived& operator =(non_const_derived&) = default;
35};
36
37struct bad_decls {
Richard Smith3003e1d2012-05-15 04:39:51 +000038 bad_decls(volatile bad_decls&) = default; // expected-error {{may not be volatile}} expected-error {{must be defaulted outside the class}}
39 bad_decls&& operator = (bad_decls) = default; // expected-error {{lvalue reference}} expected-error {{must return 'bad_decls &'}}
40 bad_decls& operator = (volatile bad_decls&) = default; // expected-error {{may not be volatile}} expected-error {{must be defaulted outside the class}}
Richard Smith55dec862011-09-30 00:45:47 +000041 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 +000042};
43
44struct A {}; struct B {};
45
46struct except_spec_a {
47 virtual ~except_spec_a() throw(A);
48 except_spec_a() throw(A);
49};
50struct except_spec_b {
51 virtual ~except_spec_b() throw(B);
52 except_spec_b() throw(B);
53};
54
55struct except_spec_d_good : except_spec_a, except_spec_b {
56 ~except_spec_d_good();
57};
58except_spec_d_good::~except_spec_d_good() = default;
59// FIXME: This should error in the virtual override check.
60// It doesn't because we generate the implicit specification later than
61// appropriate.
62struct except_spec_d_bad : except_spec_a, except_spec_b {
63 ~except_spec_d_bad() = default;
64};
65
66// FIXME: This should error because the exceptions spec doesn't match.
67struct except_spec_d_mismatch : except_spec_a, except_spec_b {
68 except_spec_d_mismatch() throw(A) = default;
69};
70struct except_spec_d_match : except_spec_a, except_spec_b {
71 except_spec_d_match() throw(A, B) = default;
72};
DeLesley Hutchinsc24a2332012-02-16 16:50:43 +000073
74// gcc-compatibility: allow attributes on default definitions
75// (but not normal definitions)
76struct S { S(); };
77S::S() __attribute((pure)) = default;