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.

20
  • 1
    What about doing it the other way around, i.e. enable -Wall globally, and -Werror only on the parts of the code you've "cleansed"? Commented Apr 30, 2013 at 14:01
  • 2
    @H2CO3 He said he's going to fix it, but in a large project I can see not wanting to deal with that first. No need to treat him like a child and keep something from him. Commented Apr 30, 2013 at 14:05
  • 2
    @H2CO3, Const correctness is a great thing, but very hard to reach in a big project, if it was neglected over years of development. To fix one simple warning, you end up changing tens of functions, which is at present out of the question. Commented Apr 30, 2013 at 14:08
  • 1
    @ugoren: not really. As long as you've got -Wall all over the place and you log your build output, a simple grep will tell you all the warnings you haven't fixed yet. Commented Apr 30, 2013 at 14:12
  • 2
    @H2CO3, starting with const correctness and keeping it as you go is great. But I'm talking about a huge project, where it was neglected for awfully long. You can't fix it in a day. Commented Apr 30, 2013 at 14:31

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

2 Comments

Phasing by module isn't so helpful. It will take a long time until we manage to have the important warnings enabled throughout our code this way. An I'm not sure what you mean by triggering a subtarget compilation.
That's right, it will take a long time, but since what you're asking in the post is not possible (disabling built-in warnings enabled by -Wall), the problem becomes how to filter the output in such a way as to make it reasonable to work with. If you work on a module basis, you can cope with all the warnings at once, because they will be inherent to a much smaller code base. Just my two cents.
0

It might be folly, but ...

Why not a simple 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

4 Comments

Another suggestion: run at least a full count of warnings with wc -l, to ensure you are not adding new warnings that are being filtered out
It's all very well for a simple compilation. But with a complicated project, lots of developers, platforms, compilation methods, this approach gets quite difficult.
@ugoren "lots of compilation methods"?? If not everyone is using the same build system then you may have bigger problems to deal with.
@MattMcNabb, We have bigger problems, but they're to complicated to post here. It doesn't mean we shouldn't solve the small ones.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.