[cfe-dev] nodes not appearing in AST?

Eli Friedman eli.friedman at gmail.com
Fri Jan 6 12:03:50 PST 2012


On Fri, Jan 6, 2012 at 11:37 AM, Robert Anderson
<rwa at alumni.princeton.edu> wrote:
>
> It seems the AST generated by libclang is missing nodes in some cases.
> Example:
>
> The AST for the program:
>
> struct A {
>    void foo() {};
> };
>
> template <class T>
> struct B {
>    void bar();
>    A m_a;
> };
>
> template <class T>
> void B<T>::bar()
> {
>    m_a.foo();
> }
>
> contains a CALL_EXPR node for the symbol foo, just as I expect:
>
> % ./c-index-test -test-print-typekind test6.cxx > out
> % grep foo out
> CXXMethod=foo:3:9 (Definition) typekind=FunctionProto [result=Void]
> [isPOD=0]
> CallExpr=foo:3:9 typekind=Dependent [isPOD=1]
> MemberRefExpr=foo:3:9 SingleRefName=[15:8 - 15:11] RefName=[15:8 - 15:11]
> typekind=Unexposed [isPOD=1]
>
> However, the program:
>
> template <class T>
> struct A {
>    void foo() {};
> };
>
> template <class T>
> struct B {
>    void bar();
>    A<T> m_a;
> };
>
> template <class T>
> void B<T>::bar()
> {
>    m_a.foo();
> }
>
> where A is now a class template, does NOT contain such a node.  The only
> node referencing foo is the declaration:
>
> % ./c-index-test -test-print-typekind test5.cxx > out
> % grep foo out
> CXXMethod=foo:4:9 (Definition) typekind=FunctionProto [result=Void]
> [isPOD=0]
>
> Can someone explain this?  Is this a bug?  How can I discover the "uses" of
> foo in this program if none of the nodes in the AST have that spelling?

In C++, you can't perform name lookup into a dependent type; we can't
actually prove what method "m_a.foo()" calls until "B<T>::bar()" is
instantiated.

-Eli




More information about the cfe-dev mailing list