LLVM:-Wno-ignored-qualifiers 等效吗?
使用 GCC,当启用 -Wall -Wextra
标志时,可以选择禁用警告,例如使用 -Wno-ignored-qualifiers
来禁用警告:
warning: 'const' type qualifier on return type has no effect
有什么办法吗?使用 LLVM/Clang 实现相同的行为?我用谷歌搜索了它,但只找到了一些关于如何添加此错误报告功能的补丁相关页面。没有关于如何禁用它的内容。
我正在使用 LLVM & Clang 版本 3.0(从 SVN 源构建)。
注意:我本来打算在 SuperUser 上发布这篇文章,但是那里没有一个关于 Clang 的问题,也没有 LLVM 标签,所以这让我感到沮丧。如果无论如何都有这个问题,请随意移动它。
[编辑] 当我从终端运行 Makefile 时,似乎可以识别该选项。然而,当从 Eclipse (Helios) 运行时,它不会被识别。
[解决方案]找到了。显然,问题是 Eclipse(在 Ubuntu 下)是由 root 启动的。为什么会这样,我不知道,但效果是 $PATH 变量包含 root 所拥有的内容,而不是启动 Eclipse 的用户所拥有的内容。因此,Eclipse 使用较旧的系统范围内安装的 Clang 版本 (2.80)。在项目属性中添加正确的 PATH 变量 -> C/C++ 构建 ->环境解决了这个问题。
With GCC, when the -Wall -Wextra
flags are enabled, one has the option of disabling warnings such as the following with -Wno-ignored-qualifiers
:
warning: 'const' type qualifier on return type has no effect
Is there any way to achieve the same behavior with LLVM/Clang? I Googled it, but only found some patch related pages about how this error reporting feature got added. Nothing on how to disable it.
I am using LLVM & Clang version 3.0 (build from SVN sources).
Note: I was going to post this on SuperUser, but there's not a single question about Clang there and no LLVM tag either, so that kind of discouraged me. If this question should be there anyway, feel free to move it.
[Edit] It seems the option is recognized when I run my Makefile from the terminal. When ran from Eclipse (Helios), it doesn't get recognized however.
[Solution] Found it. Apparently, the problem was Eclipse (under Ubuntu) is started by root. Why this is, I have no idea, but the effect is that the $PATH variable contains what root would have, instead what the user starting Eclipse would have. As such, Eclipse was using an older system-wide installed version of Clang (2.80). Adding the correct PATH variable in Project Properties -> C/C++ Build -> Environment fixed this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用什么版本的 Clang?
-Wno-ignored-qualifiers
对我有用:一般来说,您可以查看
.td
文件,它们在收集所有诊断信息方面做得非常好。 (Clang 文档中有一个 TODO 使用 tblgen 自动生成文档,但这还没有完成。)在这种情况下,例如,您可以在
DiagnosticSemaKinds.td
:显示它所在的诊断组 (
IgnoredQualifiers< /代码>)。然后您可以查看
DiagnosticGroups.td
来查看在命令行上调用了什么IgnoredQualifiers
:所以就是
-Wno-ignored-qualifiers
了。 Clang 尽可能地尝试与 GCC 兼容,因此使用 GCC 名称通常是可行的。What version of Clang are you using?
-Wno-ignored-qualifiers
works for me:In general you can look at the
.td
files, which do a pretty nice job of collecting all the diagnostics. (There's a TODO in the Clang docs to autogenerate documentation with tblgen, but this hasn't been done yet.)In this case for example you see in
DiagnosticSemaKinds.td
:which shows you what diagnostic group it's in (
IgnoredQualifiers
). Then you can look inDiagnosticGroups.td
to see whatIgnoredQualifiers
is called on the command line:So
-Wno-ignored-qualifiers
is it. Clang tries to be GCC-compatible wherever possible, so using the GCC name for something is usually likely to work.