0

I'm pretty surprise that, while this is well-formed:

int main()
{
    using T = int;
    T t;
    (void)t;
    t.~T();
}

that isn't:

int main()
{
    int t;
    (void)t;
    t.~int();
}

However, that is well-formed again:

int main()
{
    int t;
    (void)t;

    using T = int;
    t.~T();
}

I was expecting that the using declaration won't make any difference at all. Why cannot I write the pseudodestructor call using the real type name if the call is possible after all? What bullet in the standard does it forbid that?

ABu
  • 10,423
  • 6
  • 52
  • 103
  • you are looking for clever ways to shoot youself in the foot? – 463035818_is_not_an_ai Sep 28 '17 at 15:11
  • tldr; `int` is a fundamental type so there's really no point in ever writing `.~int()`, but you may need to write this in template code so `.~T()` needs to be allowed. – Barry Sep 28 '17 at 15:15
  • [This](https://stackoverflow.com/questions/46429692/explicitly-invoking-int-destructor-why-is-a-type-alias-required) fits more to the question. – nwp Sep 28 '17 at 15:15
  • 1
    @tobi303 Nou, I just refused to believe that the standard had a basic mistake, because, primitive types, according to the standard concept definitions, seemed to don't being destructibles (because they require to `u.~T()` are well-formed expressions), and thus, plain pointers were not iterators (because they are required to be destructibles), until I realized that the definitions were restricted to objects of types from template parameters, which finally brought me to do some testing and to do some asking over here. – ABu Sep 28 '17 at 15:53
  • 1
    i see. Btw I was really curious what was your motivation I just cannot help myself from sounding quite snarky sometimes ;) thanks for the reply – 463035818_is_not_an_ai Sep 28 '17 at 15:55

0 Answers0