#pragma GCC warning … with -Werror not treated as error
| Bugzilla Link | 36758 |
| Version | 6.0 |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
Extended Description
Clang seems to support #pragma GCC warning … (see https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html#Pragmas), but the messages are always treated as warnings, even when -Werror is provided.
AFAICT #pragma GCC warning … is treated as an alias for #pragma message … (the warning which is emitted says it's -W#pragma-messages). It should be treated more like #warning.
Test case is simple:
$ cat warn.c #pragma GCC warning "Hello" $ clang -Werror -c -o warn.o warn.c && echo "I shouldn't be printed" warn.c:1:13: warning: Hello [-W#pragma-messages] #pragma GCC warning "Hello" ^ 1 warning generated. I shouldn't be printed
GCC works as expected:
$ gcc -Werror -c -o warn.o warn.c && echo "I shouldn't be printed" warn.c:1:21: error: Hello [-Werror] #pragma GCC warning "Hello" ^~~~~~~ cc1: all warnings being treated as errors
As does ICC:
icc -Werror -c -o warn.o warn.c && echo "I shouldn't be printed" warn.c(1): error #1028: unknown warning specifier #pragma GCC warning "Hello" ^
compilation aborted for warn.c (code 2)
Looks like #pragma clang warning … works as expected, so I would think getting #pragma GCC warning … to work the same would be pretty straightforward.
The issue still reproduces as of Clang 16.0.0: https://godbolt.org/z/647e5vGxE
I hit this issue today.
A colleague and I were examining logs and found a mountain of -W#pragma-messages warnings though the build was passing. We were extremely confused because -Werror is enabled.
It wasn't until finding this bug report that the world made sense again. 😄
Is it on a roadmap to be fixed?
I think we agree that this is an issue, but nobody has volunteered yet to fix this.