13

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.

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.

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).

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.

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.

4

3 に答える 3

0

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43245によると「-Wdiscarded-qualifiers」になりますが、バグ修正のエントリが2014年5月1日のものなので、gccコンパイラは使用すると、サポートされない場合があります。

于 2014-11-04T23:55:07.353 に答える