https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90843
Bug ID: 90843
Summary: pragma diagnostic doesn't affect warnings controlled
by extra_warnings and pedantic
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
I thought there was a bug about this but I can't find it so let me open this
one for reference: when an aspect of a warning controlled by its own option is
also affected by -Wextra or -Wpedantic, that aspect cannot be controlled via
#pragma diagnostic.
For example, -Wbuiltin-declaration-mismatch is issued for incompatible
declarations of built-in functions. But when the declaration "closely" matches
the expected type, such as by returning a distinct integer type of the same
size, the warning is only issued when -Wextra is in effect. In such a case,
when -Wextra is set on the command line, #pragma GCC diagnostic ignored
"-Wextra" doesn't suppress this aspect of the warning.
The test case below illustrates this. In it, the first instance of the warning
is expected but the second instance is not, even though it should be suppressed
by the #pragma.
$ cat a.c && gcc -S -Wall -Wextra -Wpedantic a.c
unsigned isalpha (int);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wextra"
unsigned isdigit (int);
#pragma GCC diagnostic pop
a.c:1:10: warning: mismatch in return type of built-in function ‘isalpha’;
expected ‘int’ [-Wbuiltin-declaration-mismatch]
1 | unsigned isalpha (int);
| ^~~~~~~
a.c:5:10: warning: mismatch in return type of built-in function ‘isdigit’;
expected ‘int’ [-Wbuiltin-declaration-mismatch]
5 | unsigned isdigit (int);
| ^~~~~~~
A similar problem in the C++ front-end affects the following test case:
$ cat t.C && gcc -S -Wall -Wextra -Wpedantic t.C
#pragma GCC diagnostic warning "-Wpedantic"
int a[0]; // Wpedantic (good)
#pragma GCC diagnostic ignored "-Wpedantic"
int b[0]; // no -Wpedantic (good)
void f (int n)
{
int a[n]; // -Wvla not suppressed (bug)
(void)&a;
}
t.C:2:7: warning: ISO C++ forbids zero-size array ‘a’ [-Wpedantic]
2 | int a[0]; // Wpedantic (good)
| ^
t.C: In function ‘void f(int)’:
t.C:8:7: warning: ISO C++ forbids variable length array ‘a’ [-Wvla]
8 | int a[n]; // -Wvla not suppressed (bug)
| ^
Another similar issue was pointed out here:
https://gcc.gnu.org/ml/gcc-patches/2019-06/msg00642.html