Search code examples
c++destructorlanguage-lawyerpseudo-destructor

Unqualified pseudo-destructor-name


This simple program is accepted by EDG (ICC) but rejected by GCC and Clang.

Is it well formed? If not, why?

int main() {
    int n;
    n.~int();
}

To the curious: The program doesn't do anything and I rather doubt there's even a use case for this language feature. There's templates, but whether they generate expression syntax is debatable. Such topics aren't appropriate for this site. Nothing to see here.


EDIT: The title of this question is odd. I thought the issue was the lack of an int:: qualifier before ~int. The question was inspired by this Q&A, which encourages omission of the qualifier when invoking something like derived_object::~base_class(). This however is ill-formed and only accepted by GCC.


Solution

  • I believe this is ill-formed because ~int is not a valid pseudo-destructor-name. According to the grammar at §5.2/1, in a pseudo-destructor-name the tilde must be followed by a type-name or decltype-specifier. A type-name is a class-name, enum-name, typedef-name, or simple-template-id (§7.1.6.2/1), and int is none of these, so int is not a type-name (although it is a type-specifier).

    (References taken from N3936, i.e. the C++14 draft.)