Consider the following text:
[C++11: 12.4/11]:
Destructors are invoked implicitly
- for constructed objects with static storage duration (3.7.1) at program termination (3.6.3),
- for constructed objects with thread storage duration (3.7.2) at thread exit,
- for constructed objects with automatic storage duration (3.7.3) when the block in which an object is created exits (6.7),
- for constructed temporary objects when the lifetime of a temporary object ends (12.2),
- for constructed objects allocated by a new-expression (5.3.4), through use of a delete-expression (5.3.5),
- in several situations due to the handling of exceptions (15.3).
A program is ill-formed if an object of class type or array thereof is declared and the destructor for the class is not accessible at the point of the declaration. Destructors can also be invoked explicitly.
Then why does this program compile successfully?
#include <iostream>
struct A
{
A(){ };
~A() = delete;
};
A* a = new A;
int main() {}
// g++ -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out
Is GCC just being permissive?
I'm inclined to say so, since it rejects the following yet the standard appears to have no particular rule specific to deleted destructors in an inheritance hierarchy (the only loosely relevant wording is pertinent to the generation of defaulted default constructors):
#include <iostream>
struct A
{
A() {};
~A() = delete;
};
struct B : A {};
B *b = new B; // error: use of deleted function
int main() {}