Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dereference operator for unique_ptr does not work in Eclipse

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.

like image 859
betabandido Avatar asked Jun 22 '12 09:06

betabandido


Video Answer


1 Answers

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.

like image 83
betabandido Avatar answered Oct 16 '22 11:10

betabandido