Eclipse CDT 索引和 std::unique_ptr
我在这段代码中使用 std::unique_ptr ,它按我的预期编译和运行。
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);
但是,我从 Eclipse CDT 收到错误消息。第四行:无法解析方法“insert”,无法解析方法“end”。
以前,我在名称 std::unique_ptr 的出现上也遇到错误。这是通过设置预处理器符号 __GXX_EXPERIMENTAL_CXX0X__ 并重建索引来解决的,如 这个问题。
有没有办法让 CDT 理解 s 的类型为 std::string * 并且它应该在 std::string 中查找 s->insert() 和 s->end() ?
PS:我正在使用 Eclipse 3.7.1 和 CDT 8.0.0.201106081058
PS2:我想将其作为上述问题中的评论发布,但我不能,大概是因为我是新用户
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Eclipse CDT 索引器似乎无法推导出 unique_ptr::pointer 类型,该类型也用作运算符->() 的返回类型。当您键入类似
错误时,您会看到这一点,将“检测到”没有匹配的重载,并且唯一的候选者将是
reset(?)
。所以这显然是一个错误。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
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.此问题最近已在 cdt 8.1.1 中修复。只需转到“帮助”->“检查更新”即可下载并安装。我已经测试了 unique_ptr 并且它已正确索引。
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.
我在较新版本的 Eclipse CDT (9.3) 上也遇到同样的问题。我尝试了在互联网上找到的所有技巧,每次重建索引,希望有所改变。但索引器始终无法推断出 std::unique_ptr::operator->() 的类型。最后,我决定使用一个非常简单的解决方法:
我将
ECLIPSE_INDEXER_WORKAROUND
添加到 Eclipse 中的预处理器符号(当然仅用于索引选项,而不是构建),索引再次有用!为了减少对代码的污染,我们可以使用宏:
I have the same issue on newer version of Eclipse CDT (9.3). I tried all the tricks I found on the internet, rebuilding every time my index, hoping for a change. But the indexer was never able to deduce the type of
std::unique_ptr<T>::operator->()
. Finally, I decided to use a very simple workaround:I add
ECLIPSE_INDEXER_WORKAROUND
to preprocessor symbols (of course for indexing options only, not building) in Eclipse, and indexing is useful again!In order to pollute the code less, we can use a macro: