Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable warning/error for default warnings

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.

like image 504
ugoren Avatar asked Apr 30 '13 13:04

ugoren


People also ask

How do I turn off error warnings?

You can make all warnings being treated as such using -Wno-error. You can make specific warnings being treated as such by using -Wno-error=<warning name> where <warning name> is the name of the warning you don't want treated as an error. If you want to entirely disable all warnings, use -w (not recommended).

How do you turn off warnings in C++?

To disable a set of warnings for a given piece of code, you have to start with a “push” pre-processor instruction, then with a disabling instruction for each of the warning you want to suppress, and finish with a “pop” pre-processor instruction.

How do I turn off warnings in Python?

Use the filterwarnings() Function to Suppress Warnings in Python. The warnings module handles warnings in Python. We can show warnings raised by the user with the warn() function. We can use the filterwarnings() function to perform actions on specific warnings.

How do I suppress warnings in Vscode?

To disable TypeScript warnings in VS Code, we can set a few options in our VS Code settings to disable them. { //... "typescript. validate. enable": false, "javascript.


1 Answers

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

like image 75
Blazor Avatar answered Sep 19 '22 04:09

Blazor