LLVM:-Wno-ignored-qualifiers 等效吗?

发布于 2024-11-02 12:01:12 字数 758 浏览 0 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

π浅易 2024-11-09 12:01:12

您使用什么版本的 Clang? -Wno-ignored-qualifiers 对我有用:

% clang -Wall -Wextra -c foo.c
foo.c:1:1: warning: 'const' type qualifier on return type has no effect
      [-Wignored-qualifiers]
const int foo();
^~~~~
1 warning generated.
% clang -Wall -Wextra -Wno-ignored-qualifiers -c foo.c
%

一般来说,您可以查看 .td 文件,它们在收集所有诊断信息方面做得非常好。 (Clang 文档中有一个 TODO 使用 tblgen 自动生成文档,但这还没有完成。)

在这种情况下,例如,您可以在 DiagnosticSemaKinds.td

def warn_qual_return_type : Warning< 
  "'%0' type qualifier%s1 on return type %plural{1:has|:have}1 no effect">,
  InGroup<IgnoredQualifiers>, DefaultIgnore;

显示它所在的诊断组 (IgnoredQualifiers< /代码>)。然后您可以查看 DiagnosticGroups.td 来查看在命令行上调用了什么 IgnoredQualifiers

def IgnoredQualifiers : DiagGroup<"ignored-qualifiers">;

所以就是 -Wno-ignored-qualifiers 了。 Clang 尽可能地尝试与 GCC 兼容,因此使用 GCC 名称通常是可行的。

What version of Clang are you using? -Wno-ignored-qualifiers works for me:

% clang -Wall -Wextra -c foo.c
foo.c:1:1: warning: 'const' type qualifier on return type has no effect
      [-Wignored-qualifiers]
const int foo();
^~~~~
1 warning generated.
% clang -Wall -Wextra -Wno-ignored-qualifiers -c foo.c
%

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:

def warn_qual_return_type : Warning< 
  "'%0' type qualifier%s1 on return type %plural{1:has|:have}1 no effect">,
  InGroup<IgnoredQualifiers>, DefaultIgnore;

which shows you what diagnostic group it's in (IgnoredQualifiers). Then you can look in DiagnosticGroups.td to see what IgnoredQualifiers is called on the command line:

def IgnoredQualifiers : DiagGroup<"ignored-qualifiers">;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文