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

David Blaikie dblaikie at gmail.com
Fri Dec 16 08:07:13 PST 2011


On Mon, Dec 12, 2011 at 1:49 PM, David Blaikie <dblaikie at gmail.com> wrote:
> On Mon, Dec 12, 2011 at 1:10 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
>> 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();
>> }
>
> Ah, indeed. Sorry I missed that - thanks for the test case. I've added
> that to the existing (non-decltype) pseudodestructor tests & added
> similar/more comprehensive tests for the pseudo destructor case to my
> patch. See attached.

Wasn't sure if I should've expected another sign-off with these
changes, so I hope it's OK that I've now checked this in (r146738) -
happy for any post commit review (such as naming of the "CheckArrow"
function, etc) for the extra refactoring.

Thanks again,
- David




More information about the cfe-commits mailing list