[cfe-dev] Missing FieldDecl from macro calls and template arguments

Jeffrey Walton noloader at gmail.com
Wed Jun 15 15:39:45 PDT 2011


On Wed, Jun 15, 2011 at 6:38 PM, Jeffrey Walton <noloader at gmail.com> wrote:
> On Wed, Jun 15, 2011 at 3: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?
> Xcode does not define DEBUG (ie, -DDEBUG) for debug builds; and does
> not define NDEBUG (ie, -DNDEBUG) for release builds. You'll have to do
> it yourself under the project's settings.
>
> Per POSIX/IEEE, assert() calls abort(). If you want to change the
> [useless] behavior, use the ASSERT below (and don't use little
> assert). I'm an avid asserter - all my projects use it (from Xcode to
> Visual Studio [modified] to Linux). Its my intentions to have the code
> debug itself whenever possible.
>
My bad - I confused lists (thought it was cocoa-dev).

Jeff




More information about the cfe-dev mailing list