[cfe-dev] Traversing CompoundStmt with non-type template parameter

Philip Craig philipjcraig at gmail.com
Wed Oct 17 15:09:11 PDT 2012


On Thu, Oct 18, 2012 at 12:44 AM, Konstantin Tokarev <annulen at yandex.ru> wrote:
> Hi all,
>
> I'm trying to visit "param" in context 2:
>
> template<int param> // 1
> class B
> {
> public:
>     static void hello() { printf("%d\n", param); } // 2
> };
>
> When I run clang -cc1 -ast-dump I get
>
> template <int param> class B {
>     class B;
> public:
>     static void hello() (CompoundStmt 0x2918628 <class_template3.cpp:7:25, col:50>
>   (CallExpr 0x29185b0 <col:27, col:47> 'int'
>     (ImplicitCastExpr 0x2918598 <col:27> 'int (*)(const char *restrict, ...)' <FunctionToPointerDecay>
>       (DeclRefExpr 0x2918510 <col:27> 'int (const char *restrict, ...)' lvalue Function 0x29079d0 'printf' 'int (const char *restrict, ...)'))
>     (ImplicitCastExpr 0x2918610 <col:34> 'const char *' <ArrayToPointerDecay>
>       (StringLiteral 0x29184b8 <col:34> 'const char [4]' lvalue "%d\n"))
>     (DeclRefExpr 0x29184e8 <col:42> 'int' NonTypeTemplateParm 0x2917e70 'param' 'int')))
>
> where (DeclRefExpr 0x29184e8 <col:42> 'int' NonTypeTemplateParm 0x2917e70 'param' 'int') is what I'm looking for.
>
> However my reimplementation of VisitDeclRefExpr in RecursiveASTVisitor doesn't receive this DeclRefExpr.
>
> Dumping TemplateDecl corresponding to B results in
>
> template <int param> class B {
>     class B;
> public:
>     static void hello() (CompoundStmt 0x1f86430 <class_template3.cpp:7:25, col:50>)
> }
>
> i.e. CompoundStmt is not traversed. Its size() returns 0 and dump() doesn't show anything inside it. How do I traverse inside this CompoundStmt?

This is probably a symptom of missing a declaration for printf().
Check whether there were any errors in parsing.



More information about the cfe-dev mailing list