1 | // RUN: %clang_cc1 -verify %s -std=c++11 |
2 | // RUN: %clang_cc1 -verify %s -std=c++17 |
3 | // RUN: %clang_cc1 -verify %s -std=c++2a |
4 | |
5 | // A function that is explicitly defaulted shall |
6 | struct A { |
7 | // -- be a special member function, |
8 | A(int) = default; // expected-error {{only special member functions may be defaulted}} |
9 | A(A) = default; // expected-error {{must pass its first argument by reference}} |
10 | |
11 | // -- have the same declared function type as if it had been implicitly |
12 | // declared |
13 | void operator=(const A &) = default; // expected-error {{must return 'A &'}} |
14 | A(...) = default; |
15 | A(const A &, ...) = default; |
16 | A &operator=(const A&) const = default; |
17 | A &operator=(A) const = default; // expected-error {{must be an lvalue refe}} |
18 | #if __cplusplus <= 201703L |
19 | // expected-error@-5 {{cannot be variadic}} |
20 | // expected-error@-5 {{cannot be variadic}} |
21 | // expected-error@-5 {{may not have 'const'}} |
22 | // expected-error@-5 {{may not have 'const'}} |
23 | #else |
24 | // expected-warning@-10 {{implicitly deleted}} expected-note@-10 {{declared type does not match the type of an implicit default constructor}} |
25 | // expected-warning@-10 {{implicitly deleted}} expected-note@-10 {{declared type does not match the type of an implicit copy constructor}} |
26 | // expected-warning@-10 {{implicitly deleted}} expected-note@-10 {{declared type does not match the type of an implicit copy assignment}} |
27 | #endif |
28 | |
29 | // (except for possibly differing ref-qualifiers |
30 | A &operator=(A &&) & = default; |
31 | |
32 | // and except that in the case of a copy constructor or copy assignment |
33 | // operator, the parameter type may be "reference to non-const T") |
34 | A(A &) = default; |
35 | A &operator=(A &) = default; |
36 | |
37 | // -- not have default arguments |
38 | A(double = 0.0) = default; // expected-error {{cannot have default arguments}} |
39 | A(const A & = 0) = default; // expected-error {{cannot have default arguments}} |
40 | }; |
41 | |
42 | struct A2 { |
43 | A2(...); |
44 | A2(const A2 &, ...); |
45 | A2 &operator=(const A2&) const; |
46 | }; |
47 | A2::A2(...) = default; // expected-error {{cannot be variadic}} |
48 | A2::A2(const A2&, ...) = default; // expected-error {{cannot be variadic}} |
49 | A2 &A2::operator=(const A2&) const = default; // expected-error {{may not have 'const'}} |
50 | |
51 | struct B { |
52 | B(B&); |
53 | B &operator=(B&); |
54 | }; |
55 | struct C : B { |
56 | C(const C&) = default; |
57 | C &operator=(const C&) = default; |
58 | #if __cplusplus <= 201703L |
59 | // expected-error@-3 {{is const, but a member or base requires it to be non-const}} |
60 | // expected-error@-3 {{is const, but a member or base requires it to be non-const}} |
61 | #else |
62 | // expected-warning@-6 {{implicitly deleted}} expected-note@-6 {{type does not match}} |
63 | // expected-warning@-6 {{implicitly deleted}} expected-note@-6 {{type does not match}} |
64 | #endif |
65 | }; |
66 | |
67 | struct D : B { // expected-note 2{{base class}} |
68 | D(const D&); |
69 | D &operator=(const D&); |
70 | }; |
71 | D::D(const D&) = default; // expected-error {{would delete}} expected-error {{is const, but}} |
72 | D &D::operator=(const D&) = default; // expected-error {{would delete}} expected-error {{is const, but}} |
73 | |