[cfe-dev] Missing FieldDecl from macro calls and template arguments
Eli Friedman
eli.friedman at gmail.com
Wed Jun 15 13:13:54 PDT 2011
On Wed, Jun 15, 2011 at 12:58 PM, Adrien Chauve <adrien.chauve at gmail.com> wrote:
> On Wed, Jun 15, 2011 at 21:53, Eli Friedman <eli.friedman at gmail.com> wrote:
>> On Wed, Jun 15, 2011 at 12:27 PM, Adrien Chauve <adrien.chauve at gmail.com> wrote:
>>> Hi,
>>>
>>> I've implemented an ASTConsumer deriving from RecursiveASTVisitor to
>>> rename field names. The consumer implements VisitFieldDecl and
>>> VisitMemberExpr,
>>> but it seems that (at least) two kinds of expressions are not visited.
>>>
>>> 1- First, function arguments that are instance of templates, e.g.:
>>>
>>> template<typename T>
>>> struct Foo
>>> {
>>> int bar;
>>>
>>> void copy(const Foo<T>& other) {
>>> bar = other.bar; /// bar is visited but not other.bar
>>> }
>>> };
>>
>> other.bar in this situation is a CXXDependentScopeMemberExpr, I think...
>
> Thanks I will definitely try that!
>
>>>
>>> If I write the same code but with a non-template Foo struct, all bar
>>> member expressions are visited.
>>>
>>>
>>> 2- Code inside macros, e.g.:
>>>
>>> Foo foo;
>>> foo.bar = 2; // bar is visited
>>> assert(foo.bar == 2); // bar is not visited
>>>
>>> Do I have to get the body of the macro from the Preprocessor and make
>>> something with it?
>>
>> Are you sure you're compiling the given file with asserts enabled?
>> The expression won't show up in the AST if it gets #define'ed out.
>
> I didn't disable asserts with -DNDEBUG, so are they not enabled by default?
If you didn't define NDEBUG, they should be enabled... not sure what's
going on here. If the node is getting compiled, it should show up in
the AST, though. Maybe take a look at the output of -ast-dump?
-Eli
More information about the cfe-dev
mailing list