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
5 // A function that is explicitly defaulted shall
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}}
11 // -- have the same declared function type as if it had been implicitly
13 void operator=(const A &) = default; // expected-error {{must return 'A &'}}
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'}}
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}}
29 // (except for possibly differing ref-qualifiers
30 A &operator=(A &&) & = default;
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")
35 A &operator=(A &) = default;
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}}
45 A2 &operator=(const A2&) const;
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'}}
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}}
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}}
67 struct D : B { // expected-note 2{{base class}}
69 D &operator=(const D&);
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}}