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 .

+3


source to share


3 answers


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)

+4


source


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.

+3


source


All grammatical productions of pseudo-destructor-names require identifiers of type names, not simple type-specifiers, which is what they are int

.

So this is an EDG bug, which is unusual.

+2


source







All Articles