Unqualified pseudo-destructor-name
This simple program is accepted by the EDG (ICC), but rejected by GCC and Clang.
Is it well formed? If not, why not?
int main() {
int n;
n.~int();
}
Curious: the program does nothing, and I rather doubt that it even uses a use case for this language function. There are templates, but whether they generate expression syntax is debatable. Such themes are not suitable for this site. You can't see anything here.
EDIT: The title of this question is odd. I thought the problem was the lack of a qualifier int::
before ~int
. This question was inspired by this Q&A , which encourages qualifier exclusion when calling something like derived_object::~base_class()
. It is, however, ill-formed and only accepted by the GCC .
source to share
I believe this is ill-formed because it is ~int
not a valid pseudo-destructor-name. According to the grammar in Β§5.2 / 1, a tilde must be followed by the type name or the decltype specifier in a pseudo-destructor name. The type name is a class name, name-name, typedef-name, or simple-template-id (Β§7.1.6.2 / 1), but int
none of them, so int
it is not a type -name (although it is a type specifier).
(Links taken from N3936 i.e. C ++ 14. draft)
source to share
Pseudo-destructor-name (Β§5.2 [expr.post] / p1):
pseudo-destructor-name: nested-name-specifier_opt type-name :: ~ type-name nested-name-specifier template simple-template-id :: ~ type-name nested-name-specifier_opt~ type-name ~ decltype-specifier
Type name (Β§7.1.6.2 [dcl.type.simple] / p1):
type-name: class-name enum-name typedef-name simple-template-id
Therefore, int
it is not a type name and therefore is n.~int();
not valid.
source to share