| 1 |
// Negative test for defaulted/deleted fns. |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
void f(); // { dg-message "previous" } |
| 5 |
void f() = delete; // { dg-error "deleted" } |
| 6 |
|
| 7 |
struct A |
| 8 |
{ |
| 9 |
A() { } // { dg-message "previous" } |
| 10 |
void f() = default; // { dg-error "default" } |
| 11 |
}; |
| 12 |
|
| 13 |
A::A() = default; // { dg-error "redefinition" } |
| 14 |
|
| 15 |
void g() {} // { dg-message "previous" } |
| 16 |
void g() = delete; // { dg-error "redefinition" } |
| 17 |
|
| 18 |
struct B // { dg-message "user-provided default constructor" } |
| 19 |
{ |
| 20 |
int i; |
| 21 |
B() = default; // { dg-message "not user-provided" } |
| 22 |
}; |
| 23 |
|
| 24 |
const B b; // { dg-error "uninitialized 'const" } |
| 25 |
|
| 26 |
struct C |
| 27 |
{ |
| 28 |
virtual void f() = delete; // { dg-message "overridden" } |
| 29 |
}; |
| 30 |
|
| 31 |
struct D: public C |
| 32 |
{ |
| 33 |
virtual void f(); // { dg-error "non-deleted function" } |
| 34 |
}; |
| 35 |
|
| 36 |
struct E |
| 37 |
{ |
| 38 |
const B b; // { dg-message "should be initialized" } |
| 39 |
E() { } // { dg-error "uninitialized" } |
| 40 |
}; |
| 41 |
|
| 42 |
struct F |
| 43 |
{ |
| 44 |
F() = default; |
| 45 |
F(const F&) = delete; // { dg-message "declared" } |
| 46 |
}; |
| 47 |
|
| 48 |
struct G |
| 49 |
{ |
| 50 |
G(); |
| 51 |
}; |
| 52 |
|
| 53 |
// ctor defaulted after class defn is not trivial |
| 54 |
G::G() = default; |
| 55 |
|
| 56 |
union U |
| 57 |
{ |
| 58 |
G g; // { dg-error "union member.*non-trivial" } |
| 59 |
}; |
| 60 |
|
| 61 |
int main() |
| 62 |
{ |
| 63 |
F f; |
| 64 |
F f2(f); // { dg-error "use" } |
| 65 |
const B* b = new const B; // { dg-error "uninitialized const" } |
| 66 |
U u; // { dg-error "deleted" } |
| 67 |
} |
| 68 |
|
| 69 |
// { dg-prune-output "implicitly deleted because" } |