[cfe-commits] [patch] Support decltype in destructor calls
Eli Friedman
eli.friedman at gmail.com
Wed Dec 7 15:44:36 PST 2011
On Wed, Dec 7, 2011 at 3:07 PM, David Blaikie <dblaikie at gmail.com> wrote:
> Here's a small patch to implement the use of decltype in (non-pseudo)
> destructor calls like so:
>
> struct foo { };
> void func(foo* f) {
> f->decltype(*f)();
> }
>
> I thought I'd send this out as a small, easier to digest code review,
> even though it doesn't cover all cases (the most obvious/useful cases
> are in templates with dependent types in the expression. The problem
> there is that clang parses those conservatively as pseudo destructor
> calls & it'll take a bit more work to plumb this solution through that
> code).
+ParsedType Sema::getDestructorType(const DeclSpec& DS, ParsedType ObjectType) {
+ if (DS.getTypeSpecType() == DeclSpec::TST_error)
+ return ParsedType();
+ assert(DS.getTypeSpecType() == DeclSpec::TST_decltype
+ && "only get destructor types from declspecs");
+ QualType T = DS.getRepAsExpr()->getType();
You can't just use getType() here; you need Sema::BuildDecltypeType().
This causes some minor issues: specifically, your testcase that does
"x->~decltype(*x)();" isn't actually valid.
Also, I think you need to check if the T is dependent.
The patch looks okay otherwise.
-Eli
More information about the cfe-commits
mailing list