Search code examples
c++eclipsec++11gcceclipse-cdt

Eclipse indexer shows false-positive semantic errors


I've recently updated to Eclipse Mars.2 (version 4.5.2) and switched my project to C++11 development (yeah, it's about time!).

I've managed to configure all my Makefiles to build correctly (ie. no obvious errors or warnings) but the Eclipse built-in indexer reports several false-positive semantic errors. Not all of them have to do with C++11 specific features.

I'm referring to already existing threads [1] and [2] which are older and haven't brought any real solution for me.

False-positives examples

std::next(..) not recognized - but I have no problems with std::begin() or std::end():

std::vector<int> v;
for (auto i = std::begin(v); i != std::end(v); i++)
{
  std::next(i);
}

Invalid arguments ' Candidates are: #0 next(#0, std::iterator_traits<#0>::difference_type) Semantic Error

std::string::substr(..) not recognized:

std::string myString = "test";
myString.substr(0, 1);

Invalid arguments ' Candidates are: std::basic_string,std::allocator> substr(?, ?) Semantic Error

googletest's ASSERT_EQ macro is not not recognized (however, other assertions work!):

std::string expValue = "test";
std::string actValue = "test";
ASSERT_EQ(expValue, actValue);

Function 'Compare' could not be resolved
Semantic Error


I've tested various project settings and I came to the conclusion that it has something to do with the Eclipse project's "Paths and Symbols" settings as well with the "Preprocessor Include Paths, Macros, etc." settings. Especially the order of the Providers is highly sensitive for any changes.

The additional problem is that I have an older system with gcc 4.4.4 compiler (default in /usr/bin/gcc) and an additional gcc 4.8.2 installed in /opt/... which shall be actually used for compilation. This also means that I have two sets of header files but only one includes the C++11 features.

My current configuration is this (as seen in Project Settings -> C/C++ General -> Preprocessor Includes Paths -> Entries):

  • CDT User Settings Entries
    • system headers of gcc 4.8.2 (treated as built-in)
    • preprocessor macro __cplusplus = 201103L
  • CDT Managed Build Settings Entries
    • paths to custom includes and library paths
  • CDT GCC Build Output Parser
  • CDT GCC Built-in Compiler Settings
    • non-changeable system headers of gcc 4.4.4
    • local includes

I have tried other combinations as well but this one gives me lowest amount of false-positive errors.


The indexer has project specific settings enabled. I haven't found any switch so far that makes the errors go away.


Has anybody experienced such problems as well? Is it a configuration issue of my paths and symbols or is it a bug in the Eclipse indexer?


Solution

  • I updated Eclipse CDT to version 8.8.1 and the false-positive compile errors don't show up anymore. So after all it was a software bug.