C++ 关闭 eclipse 错误(这不是真正的错误)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14131939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 18:01:43  来源:igfitidea点击:

Turn off eclipse errors (that aren't really errors)

c++c++11eclipse-cdt

提问by soandos

Possible Duplicate:
Disable Eclipse's error discovery. (Codan false positives)

可能重复:
禁用 Eclipse 的错误发现。(Codan 误报)

With GCC 4.8/Clang 3.3 C++ support so far ahead of what Eclipse is doing with syntax checking (in terms of feature support), Eclipse is marking many things as errors that are actually valid code (template aliasing happens to be my main problem, but there are other issues as well).

由于 GCC 4.8/Clang 3.3 C++ 支持远远领先于 Eclipse 的语法检查(在功能支持方面),Eclipse 将许多事情标记为实际上是有效代码的错误(模板别名恰好是我的主要问题,但是还有其他问题)。

When I compile (or attempt to anyway, having some issues, see herefor more) whatever compiler happens to be doing the work does its job, and its errors get propagated through, but the code that it says is OK is still underlines (red and gold spiders for errors and warnings respectively), which makes it much harder to see what is going on.

当我编译(或尝试无论如何,遇到一些问题,请参阅此处了解更多信息)时,任何编译器碰巧在做这项工作都会完成它的工作,并且它的错误会传播,但它所说的代码仍然是下划线(红色和金蜘蛛分别用于错误和警告),这使得查看正在发生的事情变得更加困难。

Is there a way to get rid of these errors/warnings?

有没有办法摆脱这些错误/警告?

Even better would be a way to get rid of warnings only after compile attempt, and for as long as the relevant parts of the code don't change, but still leave them enabled in general.

更好的是一种仅在编译尝试后消除警告的方法,只要代码的相关部分不改变,但仍然保持启用它们。

(Actually the best would be a plugin for Eclipse that supports all, or at least more of C++11 than Juno does by itself, but I can't seem to find that)

(实际上,最好的 Eclipse 插件支持所有或至少比 Juno 本身更多的 C++11,但我似乎找不到)

采纳答案by Ali

UPDATE:It's been a long time since I posted the original answer and it has become outdated. I double-checked today (Mar 15, 2014): in Eclipse Kepler (Build id 20130614-0229) it is sufficient to

更新:自从我发布原始答案以来已经很长时间了,它已经过时了。我今天(2014 年 3 月 15 日)再次检查:在 Eclipse Kepler(构建 ID 20130614-0229)中,足以

  • add under Project > Properties > C/C++ Build > Settingsthen on the Tool Settingstab GCC C++ Compiler > Miscellaneousthe -std=c++11flag,

  • then under Window > Preferences > C/C++ > Build > Settingson the Discoverytab chose CDT GCC Built-in Compiler Settingsand add the -std=c++11flag to Command to get compiler specs. On my machine it looks like this after the change:

    ${COMMAND} -E -P -v -dD -std=c++11 "${INPUTS}"

  • clean and rebuild both your project andyour index (Project > C/C++ Index > Rebuild) as Eclipse tends to cache error messages and show them even though they are gone after changing the settings.

  • 下添加项目>属性> C / C ++编译>设置然后在工具设置选项卡 GCC C ++编译器>其它-std=c++11标志,

  • 然后在发现选项卡上的Window > Preferences > C/C++ > Build > Settings 下选择CDT GCC Built-in Compiler Settings并将标志添加到Command 以获取编译器规范。在我的机器上,更改后看起来像这样: -std=c++11

    ${COMMAND} -E -P -v -dD -std=c++11 "${INPUTS}"

  • 清理并重建您的项目索引(Project > C/C++ Index > Rebuild),因为 Eclipse 倾向于缓存错误消息并显示它们,即使它们在更改设置后消失了。

This works on my machine for sure.If it doesn't on yours, then you might want to give a shot to this: C++11 full support on Eclipsealthough I am neither sure about the correctness of this approach nor was it necessary to do it on my machine. As of March 7, 2014 users claimthat it helped them whereas the above approach didn't.

这肯定适用于我的机器。如果它不在你的身上,那么你可能想试一试:C++11 对 Eclipse 的完全支持,尽管我不确定这种方法的正确性,也没有必要在我的机器上这样做。截至 2014 年 3 月 7 日,用户声称它帮助了他们,而上述方法没有。



The original post, now outdated:

原来的帖子,现在已经过时了:

These bogus errors come from Codan. The whole thing is because Codan and the compiler have different understanding of C++ andCodan is buggy.

Possible workarounds

  1. Click on the project properties, then C/C++ General > Code Analysis > Syntax and Semantic Errorsand deselect whatever false errors you are getting. Drawback: you will most likely end up disabling most of the errors and warning one by one, which is quite annoying.

  2. Disable the static analysis completely at C/C++ General > Code Analysis > Syntax and Semantic Errors. You won't get the true errors from Codan but only later from the compiler.

None of them is a solution but at least you can still use the Eclipse IDE.

这些虚假错误来自Codan。整个事情是因为柯顿和编译器有C ++的不同理解柯顿是马车

可能的解决方法

  1. 单击项目属性,然后单击C/C++ General > Code Analysis > Syntax and Semantic Errors并取消选择您遇到的任何错误错误。缺点:你很可能最终会禁用大部分错误并一一警告,这很烦人。

  2. C/C++ General > Code Analysis > Syntax and Semantic Errors完全禁用静态分析。您不会从 Codan 那里得到真正的错误,而只会在稍后从编译器那里得到真正的错误。

它们都不是解决方案,但至少您仍然可以使用 Eclipse IDE。

回答by Kocka

Go to Window->Preferences write analysis into the search field select C/C++->Code Analysis and there you can turn off everything.

转到 Window->Preferences write analysis into the search field 选择 C/C++->Code Analysis,然后您可以关闭所有内容。