Search code examples
c++eclipseeclipse-cdt

Eclipse cannot resolve fields declared with macro


I've recently started diving into the code of an open source project, which is largely written in C++. I'm using Eclipse 3.8 in Ubuntu 12.10.

THE PROBLEM: Eclipses is incorrectly flagging fields as unresolved because of a particularly elaborate convention used to separate field declarations out of the header files.

someclass.h

class SomeClass
{
public:
    #define MACRO_CLASS_PARAM(Name) SomeType m_##Name;
    #include "fields.h"
    #undef MACRO_CLASS_PARAM
};

fields.h

MACRO_CLASS_PARAM(Field1)
MACRO_CLASS_PARAM(Field2)
...

Now in the cpp file, if I want to do something like instanceOfSomeClass.Field1 Eclipse will flag it as an error with "Field 'Field1' could not be resolved".

THE QUESTION: Is there any way to get Eclipse to correctly handle this situation?


Solution

  • The inability to correctly process #include statements that are not at global scope is a long-standing deficiency in Eclipse's indexer.

    Things you could do about it:

    • Revise your code to avoid this pattern. Once the textual header inclusion model is superseded by C++ Modules, it's going to be invalid anyways.
    • Contribute a fix for this deficiency to Eclipse CDT.
    • Use a different IDE that can parse this pattern. (I don't know of one off the top of my head, but I also haven't spent a lot of time looking.)