Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse CDT code analysis thinks size_t is ambiguous

Tags:

eclipse-cdt

It does, after all, get defined in stddef.h AND c++config.h:

c++config.h:

namespace std
{
  typedef __SIZE_TYPE__     size_t;
  typedef __PTRDIFF_TYPE__  ptrdiff_t;

#ifdef __GXX_EXPERIMENTAL_CXX0X__
  typedef decltype(nullptr) nullptr_t;
#endif
}

stddef.h:

typedef __SIZE_TYPE__ size_t;

So when a file does using namespace std, the Eclipse CDT code analysis gets confused and says the symbol is ambiguous. I don't know how gcc works around this, but does anybody have any suggestions on what to do for the eclipse code analysis?

like image 715
Chris Avatar asked Jul 01 '13 22:07

Chris


2 Answers

I got around this by just completely disabling that error in code analysis.

Project -> Properties -> C/C++ General -> Code Analysis

Uncheck 'Ambiguous problem'

like image 124
Chris Avatar answered Oct 16 '22 03:10

Chris


It is mostly, but not entirely, true that valid C code is also valid C++ code. You've hit a case where that's not true. This question has a very good answer about the difference in this case: Repeated typedefs - invalid in C but valid in C++? It's also worth noting that C11 will fix this incompatibility.

The upshot, really, is that this behavior is somewhere between a deficiency and a defect in the CDT code analysis. CDT ought to know that the code is C++ and to allow the syntax, but it seems as if it thinks it's C and is disallowing it.

like image 35
eh9 Avatar answered Oct 16 '22 04:10

eh9