Explicitly calling `int` destructor - why do I need an alias of type?

The next program ...

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

not compiling (see match viewer ):

  • clang ++ trunk, with -std=c++1z

  • g ++ trunk, with -std=c++1z

  • CL 19 2017


A representation of a type alias for int...

int main()
{
    using X = int;
    int{1}.~X();
}

... makes the program valid for all the previously mentioned compilers without warnings (see match mapping ).

Why is a type alias needed when calling intdestructor? Is this because it is intnot a valid grammar element for invoking destruction?

+6
source share
1

, , :

[expr.post]/1:

postfix-expression:
    postfix-expression . pseudo-destructor-name
    postfix-expression -> pseudo-destructor-name

pseudo-destructor-name:
    ~ type-name
    ~ decltype-specifier

[dcl.type.simple]/1:

type-name:
  class-name
  enum-name
  typedef-name
  simple-template-id

, type-name. [expr.pseudo]/1 , void:

-- . → , decltype. (), void. - .

, ( ), - decltype:

auto a = int{1};
a.~decltype(a)();
+9

All Articles