7

After following the steps in this post I managed to make Eclipse (Indigo) recognize unique_ptr (and other C++11 new stuff). The problem is that operator-> for unique_ptr seems not to be supported in Eclipse. Here you have an example:

class Foo { void bar() { /* ... */ } };

std::unique_ptr<Foo> foo;
(*foo).bar(); // 1
foo->bar();   // 2

Case 1 works as expected: there is no error and autocompletion works. For case 2, however, Eclipse marks the statement with an error ("Method 'bar' could not be resolved"), plus autocompletion from foo-> does not work.

Most interestingly, I do not have any problems with std::shared_ptr. It only happens for std::unique_ptr.

Has anyone experienced the same problem? Does anyone know a way to fix it?

EDIT: just for clarifying purposes, the compilation process goes fine for the code snippet shown above. So, the problem is not in the compiler itself, but on Eclipse.

Community
  • 1
  • 1
betabandido
  • 18,946
  • 11
  • 62
  • 76
  • @dirk: the question is about autocompletion and static lint-picking in the IDE; no mention of compilation issues. – Rook Jun 22 '12 at 10:21
  • @dirkgently I am using g++ 4.6, so compilation goes fine. The problem only affects to Eclipse. – betabandido Jun 22 '12 at 10:22
  • @Rock: Right. I missed that bit. – dirkgently Jun 22 '12 at 10:23
  • 1
    Even the compilers do not yet fully support C++11, so I would expect eclipse (which is notoriously behind) to support all of it it only far after the compilers do. – PlasmaHH Jun 22 '12 at 10:26
  • I used to develop C++ application with CDT, but I found its approach (understanding C++ semantics on its own, thus giving you errors without relying on an external compiler) abysmal. Fun impossible exercise: try to make eclipse not complaining about CLOCKS_PER_SEC (which is obviously a macro which isn't defined in any header since it's "virtual") being undefined. They should do something like what XCode does: integrate CDT with LLVM's wonderful infrastructure and use it. In the meanwhile, I switched back to GVim, I'm an happier developer. – akappa Jun 22 '12 at 12:45

2 Answers2

1

I have finally found a bug report in CDT describing the very same problem that I am suffering. So far, there is not a real fix for the problem but there is a workaround explained in that bug report:

Yes, GCC 4.5 is the latest GCC version whose library headers can be accurately indexed by CDT. The main reason for failing to index 4.6 headers is CDT's lack of support for 'constexpr' and 'nullptr', which are used extensively in the 4.6 headers (any chance of that being implemented for Juno, by the way?).

I have worked around this by having both GCC 4.5 and 4.6 installed on my system, and pointing CDT to 4.5's headers (by setting the compiler invocation command to 'g++-4.5' in Discovery Options) while actually compiling with 4.6.

betabandido
  • 18,946
  • 11
  • 62
  • 76
0

This issue has been recently fixed, in cdt 8.1.1. Just go help->check for updates and it will be downloaded and installed. I've tested unique_ptr and it is properly indexed.

Fauth
  • 737
  • 4
  • 11