[cfe-dev] Getting the FieldDecl from a CXXDependentScopeMemberExpr

Adrien Chauve adrien.chauve at gmail.com
Wed Jun 22 10:05:08 PDT 2011


Thanks a lot!

If I understand well, the AST is of little help for dependent names
inside template classes.
Is there any tool to deal with it? Without instanciation, can we do
anything with class templates?

Adrien

On Tue, Jun 21, 2011 at 19:36, John McCall <rjmccall at apple.com> wrote:
> On Jun 21, 2011, at 10:08 AM, Adrien Chauve wrote:
>> I'm using the following code in an ASTConsumer/RecursiveASTVisitor:
>>
>>   bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr* expr)
>>   {
>>        // skip accesses that are not written in the sources
>>        if (expr->isImplicitAccess())
>>                return true;
>>
>>        DeclRefExpr* decl_ref_expr = dyn_cast<DeclRefExpr>(expr->getBase());
>>        assert(decl_ref_expr);
>
> Instead of dyn_cast / assert, you should use cast<DeclRefExpr>.
>
>>        ValueDecl* v = decl_ref_expr->getDecl();
>>        VarDecl* var_decl = dyn_cast<VarDecl>(v);
>>        assert(var_decl);
>>
>>        const Type* t = var_decl->getType().getTypePtr();
>>        assert(t);
>>        assert(t->isDependentType()); // Ok
>>        //assert(t->isRecordType());    // Error
>>
>>        return true;
>>   }
>>
>> I'm trying to get the FieldDecl but I have no clue where to go from
>> this code...
>> The assert(t->isRecordType()) fails and I don't know why (because it's
>> a dependent type?).
>
> Yes, because it's a dependent type.
>
> We make CXXDependentScopeMemberExprs in precisely the situations
> where we can't resolve the member down to something.  There is no way
> to figure out the field here;  it could be totally different fields depending on
> how the code is instantiated.  Your code just has to deal with the fact
> that you often can't resolve things within a template pattern.
>
> John.
>




More information about the cfe-dev mailing list