2
votes

I am trying to use Eclipse CDT (just for the 'organize includes' functionality) on OS X for a C++ project. The static analyzer (syntax highlighting) doesn't seem to be able to resolve the type of a template operator overload in container classes, such as std::vector and operator[]. Example:

#include <vector>

int main() {
  std::vector<std::vector<int> > st = {{0}};

  st[0].size(); // Method 'size' could not be resolved
  st.front().size(); // no problem
}

This code compiles in g++ and clang++. I am not excited about turning off syntax highlighting completely (what's the point of the IDE?). Any ideas on getting Eclipse CDT (specifically Neon.3 Release (4.6.3) on OS X) to understand this?

EDIT: Updated with a simpler MWE, the problem was not related to using a struct.

EDIT: Added Eclipse CDT version.

1
Is this an actual compilation error or a CDT error ? If CDT it's not the best at this. I ended up turning CDT highlighting off. - Richard Critten
To me the code is fine. Unrelated: suggestion: don't use all capital identifiers. - Jabberwocky
Another unrelated suggestion: don't use typedef struct in C++. struct st { int i; }; would be just fine. - zett42
I don't have access to a Mac at the moment to test this, but I have tried this on all versions of Eclipse for the last 5 years, g++ 4.8/5/6 and clang++ 4 (on Linux 64-bit) and all of them work. Can you provide an error report with your versions please? bugs.eclipse.org/bugs/enter_bug.cgi?product=CDT - Jonah Graham
@MichaelWalz true, I was trying to make it very clear. Updated, don't want to be a bad influence. - Rakurai

1 Answers

1
votes

Eclipse is not compiling your code every time you type something new but it uses a tool for static StaticAnalysis. Unfortunately that tool is not perfect and things like this happen. https://wiki.eclipse.org/CDT/designs/StaticAnalysis