Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse CDT indexing and std::unique_ptr

I am using std::unique_ptr in this piece of code which compiles and runs as I expected.

std::stringstream out;
out << std::setw(3) << std::setfill('0') << i;
std::unique_ptr<std::string> s(new std::string(out.str()));
s->insert(s->end()-2, 1, '.');
return std::move(s);

However, I am getting error messages from Eclipse CDT. At the fourth line: Method 'insert' could not be resolved, Method 'end' could not be resolved.

Previously, I was also getting errors on appearances of the name std::unique_ptr. This was solved by setting the pre-processor symbol __GXX_EXPERIMENTAL_CXX0X__ and rebuilding the index, as described in the answer to this question.

Is there a way to make CDT understand that s is of type std::string * and that it should look in std::string for s->insert() and s->end() ?

PS: I am using Eclipse 3.7.1 and CDT 8.0.0.201106081058

PS2: I would have liked to post this as a comment in the above question, but I can't, presumably because I am a new user

like image 994
engineerX Avatar asked Jan 17 '12 03:01

engineerX


2 Answers

It seems as if the Eclipse CDT indexer is not able to deduce the unique_ptr::pointer type that is also used as the return type of operator->(). You can see this when you type something like

std::unique_ptr<Type *> ptr;
ptr.reset(new Type);

an error will be "detected" that there would be no matching overload, and that the only candidate would be reset(?). So this is obviously a bug.

like image 135
Denis Washington Avatar answered Sep 23 '22 07:09

Denis Washington


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.

like image 28
Felipe Avatar answered Sep 26 '22 07:09

Felipe