[cfe-dev] Getting the FieldDecl from a CXXDependentScopeMemberExpr

Adrien Chauve adrien.chauve at gmail.com
Tue Jun 21 10:08:03 PDT 2011


Hi,

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);

        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;
   }

This AST visitor function is used on this code:

    template<typename T>
    struct Foo
    {
        T bar;
        Foo(const Foo<T>& rhs) { bar = bar.x; }
    };


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?).

So I have a VarDecl* or a Type* that is a dependent type, but I don't
know how to extract much more information from these two.

Thanks for your help,
Adrien



More information about the cfe-dev mailing list