禁用默认警告的警告/错误

时间:2022-07-25 18:51:03

We want to start using -Wall -Werror on a large project.
Due to the size, this change has to be phased, and we want to start with the most important warnings first.

我们想在大型项目上开始使用-Wall -Werror。由于尺寸的原因,这种变化必须分阶段进行,我们首先要从最重要的警告开始。

The best way to do it seems to be using -Wall -Werror, with exceptions for specific warnings. The exceptional warnings are those which we have a lot of (so fixing them all is hard and risky), and we don't consider them very dangerous.
I'm not saying we don't want to fix all these warnings - just not on the first phase.

最好的方法似乎是使用-Wall -Werror,特殊警告的例外情况。特殊的警告是那些我们有很多的警告(因此修复它们都很困难且风险很大),我们认为它们并不危险。我不是说我们不想解决所有这些警告 - 只是不在第一阶段。

I know two ways to exclude a warning from -Werror - the best is -Wno-error=xxx, and if it doesn't work - -Wno-xxx (of course, we prefer to see the warning and ignore it, rather than hide it).

我知道从-Werror中排除警告的两种方法 - 最好是-Wno-error = xxx,如果它不起作用 - -Wno-xxx(当然,我们更愿意看到警告并忽略它,而不是把它藏起来)。

My problem is with warnings which are enabled by default, and don't have a -Wxxx flag related to them. I couldn't find any way to alllow them when -Werror is used.

我的问题是默认情况下启用的警告,并且没有与它们相关的-Wxxx标志。当使用-Werror时,我找不到任何方法来全部使用它们。

I'm specifically concerned about two specific warnings. Here's a program that exhibits them and the compiler output:

我特别关注两个具体的警告。这是一个展示它们和编译器输出的程序:

#include <stdio.h>
void f(int *p) { printf("%p\n", p); }

int main(int argc, char *argv[]) {
        const int *p = NULL;
        const unsigned int *q = NULL;
        f(p);           /* Line 7: p is const, f expects non const */
        if (p == q) {   /* Line 8: p is signed, q is unsigned */
                printf("Both NULL\n");
        }
        return 0;
}

% gcc warn.c
warn.c: In function 'main':
warn.c:7: warning: passing argument 1 of 'f' discards qualifiers from pointer target type
warn.c:8: warning: comparison of distinct pointer types lacks a cast

I know the best solution is to fix these warnings, but it's much easier said than done. In order for this change to be successful, we have to do this phased, and can't do too many changes at once.

我知道最好的解决方案是修复这些警告,但说起来容易做起来难。为了使这一变化取得成功,我们必须分阶段进行,并且不能同时进行太多更改。

Any suggestions? Thanks.

有什么建议么?谢谢。

3 个解决方案

#1


1  

What about phasing on a compilation unit/module/library basis instead of per warning? Is triggering a subtarget compilation an option (a good-enough build system in place)?

如何逐步完成编译单元/模块/库的基础而不是每次警告?触发子目标编译是一个选项(一个足够好的构建系统)?

#2


0  

It might be folly, but ...

这可能是愚蠢的,但......

Why not a simple grep ?

为什么不是一个简单的grep?

something like

就像是

 gcc teste.c 2>&1 | grep -v 'comparison of distinct' | grep -v 'some_other_string'

You probably want to hide these greps in a script, and call the script from your makefile instead of gcc

您可能希望在脚本中隐藏这些greps,并从makefile而不是gcc调用脚本

#3


0  

According to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43245 it will be "-Wdiscarded-qualifiers", but since the bug-fixed entry is from May 1, 2014, the gcc compiler you are using might not support it.

根据https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43245,它将是“-Wdiscarded-qualifiers”,但由于错误修复的条目是从2014年5月1日开始,你是gcc编译器使用可能不支持它。

#1


1  

What about phasing on a compilation unit/module/library basis instead of per warning? Is triggering a subtarget compilation an option (a good-enough build system in place)?

如何逐步完成编译单元/模块/库的基础而不是每次警告?触发子目标编译是一个选项(一个足够好的构建系统)?

#2


0  

It might be folly, but ...

这可能是愚蠢的,但......

Why not a simple grep ?

为什么不是一个简单的grep?

something like

就像是

 gcc teste.c 2>&1 | grep -v 'comparison of distinct' | grep -v 'some_other_string'

You probably want to hide these greps in a script, and call the script from your makefile instead of gcc

您可能希望在脚本中隐藏这些greps,并从makefile而不是gcc调用脚本

#3


0  

According to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43245 it will be "-Wdiscarded-qualifiers", but since the bug-fixed entry is from May 1, 2014, the gcc compiler you are using might not support it.

根据https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43245,它将是“-Wdiscarded-qualifiers”,但由于错误修复的条目是从2014年5月1日开始,你是gcc编译器使用可能不支持它。