[Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Jun 28 20:40:17 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |NEW
--- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> ---
There's still more work to do to make the argument location available to the
warning code (e.g., when passing the literal 0 or nullptr, or to the middle
end) so I'm going to leave this open, but for the following variant of the test
case in comment #0 GCC now prints the warnings below:
$ cat pr86568.C && gcc -O2 -S -Wall pr86568.C
void f(void*, void*) __attribute__((nonnull(2)));
struct A {
void f(void*, void*) __attribute__((nonnull(2)));
};
int main()
{
void * const p = 0;
f(p, p);
A().f(p, p);
}
pr86568.C: In function ‘int main()’:
pr86568.C:11:8: warning: argument 2 null where non-null expected [-Wnonnull]
11 | f(p, p);
| ^
pr86568.C:1:6: note: in a call to function ‘void f(void*, void*)’ declared
‘nonnull’
1 | void f(void*, void*) __attribute__((nonnull(2)));
| ^
pr86568.C:12:9: warning: argument 1 null where non-null expected [-Wnonnull]
12 | A().f(p, p);
| ^
pr86568.C:4:8: note: in a call to function ‘void A::f(void*, void*)’ declared
‘nonnull’
4 | void f(void*, void*) __attribute__((nonnull(2)));
| ^
More information about the Gcc-bugs
mailing list