1

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?

Community
  • 1
  • 1
Markus L
  • 932
  • 2
  • 20
  • 38
  • 1
    Are you sure this is the indexer and not the `code analyzer`? I just turned the `code analyzer` off, the compiler does a good enough job of pointing out such errors. – Galik Mar 02 '16 at 18:54
  • Also it looks like you have strange User Settings. Maybe this will help with configuring for `C++11` https://stackoverflow.com/questions/17131744/eclipse-cdt-indexer-does-not-know-c11-containers/24628885#24628885 – Galik Mar 02 '16 at 18:58
  • @Galik: Configuring the providers like in the mentioned thread means that I have to put my referenced library headers in the "CDT User Settings Entries". I tried that but after rebuilding the index it leads to exactly the same situation: The same function calls are marked as erroneous. – Markus L Mar 04 '16 at 08:28
  • @Galik disabling the semantic errors in the `code analyzer` settings really removes the false-positive error marks! However, I think that only hides the actual problem (either a bug in Eclipse or a bad configuration in my project settings). – Markus L Mar 04 '16 at 08:48

2 Answers2

1

std::next(i); is incorrect. When you use

for (auto i : v)
{
    std::next(i);
}

i becomes of the type *(v.begin()) which in your code is an int. std::next requires an iterator and that iterator must also provide a difference_type type.

The whole purpose of a ranged based for loop is to not have to worry about advancing through the container. If you wanted to print everything out of the vector you would just use

for (auto i : v)
{
    std::cout << i << " ";
}

I know this doesn't solve your other error but it fixes the first one

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
  • Yes, you're right. I tried to show simplified examples of my code that doesn't work. I simplified too much! I fixed my examples.They compile now without any errors or warnings together with my project code. Eclipse still shows errors. – Markus L Mar 03 '16 at 08:54
1

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.

Markus L
  • 932
  • 2
  • 20
  • 38