[cfe-commits] [patch] Support decltype in pseudodestructor/dependent destructor calls

Eli Friedman eli.friedman at gmail.com
Mon Dec 12 13:10:09 PST 2011


On Mon, Dec 12, 2011 at 12:25 PM, David Blaikie <dblaikie at gmail.com> wrote:
> On Mon, Dec 12, 2011 at 11:18 AM, Eli Friedman <eli.friedman at gmail.com> wrote:
>> On Sun, Dec 11, 2011 at 8:27 PM, David Blaikie <dblaikie at gmail.com> wrote:
>>> Here's the finishing touches on decltype in explicit destructor calls
>>> - supporting pseudodestructor calls and destructor calls on dependent
>>> types (which are handled by Clang in a similar way to pseudodestructor
>>> calls):
>>>
>>> typedef int foo;
>>> foo f;
>>> f.~decltype(foo())();
>>>
>>> template<typename T>
>>> void func(T* t) {
>>>  t->~decltype(T())();
>>> }
>>>
>>> etc...
>>
>> Patch looks fine.
>
> Thanks Eli - actually, as I was going to check this in & remembered
> I'd wanted to refactor the arrow-testing logic I'd shamelessly
> copy-pasted from one of the other pseudo-destructor parsing functions.
> (it tests for arrow uses that should be '.') See
> SemaExprCXX.cpp:4327-4345, repeated at 4445-4463, and then repeated
> again in my patch.
>
> I moved this logic into a common, static, utility function - but then
> I got thinking. How/when does this actually occur? Since
> pseudodestructors can destroy any object, it seems impossible for us
> to ever correctly diagnose an erroneous '->' that should be a '.'
> before we've seen the type on the right of the '~'. So I replaced the
> diag+fixit with an assertion & ran the test suite. It never fires.
>
> I tested the following for cases:
>
> struct foo { void bar(); };
> void func(foo* f, foo& g) {
>  f.~foo();
>  f->~foo();
>  g.~foo();
>  g->~foo();
> }
>
> and none of them produce the -> fixit:
>
> arrow.cpp:3:6: error: the type of object expression ('foo *') does not
> match the type being destroyed ('foo') in pseudo-destructor
>      expression
>  f.~foo();
>  ~  ^~~
> arrow.cpp:6:4: error: member reference type 'foo' is not a pointer
>  g->~foo();
>  ~^
>
> It seems this code is dead, so far as I can tell. Should I delete the
> existing two instances of it & remove the one I was going to add to my
> code?

Try:

typedef int foo;
void func(int x) {
  x->~foo();
}

-Eli




More information about the cfe-commits mailing list