Search code examples
c++eclipsec++11ideeclipse-cdt

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


Solution

  • 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.