Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I enable -Werror using a GCC pragma?

Tags:

c++

c

gcc

I have a few files where I'd like to be strict about warnings, and I use GCC to build my project.

I've tried #pragma GCC diagnostic error "-Wall" as per 6.57.10 Diagnostic Pragmas, but it fails to account for some other enabled warning types:

foo.c:666:6: warning: passing argument 2 of 'bar' from incompatible pointer type [-Wincompatible-pointer-types]

Is there a way to enable -Werror for the file like it was supplied from the command line (or, at least, for the implicitly enabled set of warnings), so any warning would trigger an error?

like image 476
L29Ah Avatar asked Nov 07 '22 12:11

L29Ah


1 Answers

For this case, you can use

#pragma GCC diagnostic error "-Wincompatible-pointer-types"

as for example in

#pragma GCC diagnostic error "-Wincompatible-pointer-types"
void foo(int * a)
{
}

void bar() {
        foo("foo");
}

Using -Wall with this pragma is not supported. Only diagnostic options are supported, that are shown with -fdiagnostics-show-option (which is the default today anyway), as in your example warning above.

like image 107
Ctx Avatar answered Nov 14 '22 01:11

Ctx