3

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?

Justin Smith
  • 149
  • 1
  • 2
  • 9
  • try this http://stackoverflow.com/questions/8148235/eclipse-cdt-shows-semantic-errors-but-compilation-is-ok – Gilad Feb 26 '13 at 21:09
  • I don't think that's the same issue. My guess at my problem is that the analyzer isn't expanding the included file and macro, so it doesn't see the field declarations and therefor doesn't think they exist. I did play around with some of the suggestions on that topic though, and non worked – Justin Smith Feb 26 '13 at 22:11

1 Answers1

2

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.)
HighCommander4
  • 50,428
  • 24
  • 122
  • 194