Created attachment 52986 [details] minified example program to show the false positive Option -Wall also enables -Waddress, which causes a lot of false positives like shown in my attached example problem (minimized and anonymized real world example): waddress.c: In function ‘comp_has_ExtraPtr’: waddress.c:44:29: warning: the comparison will always evaluate as ‘true’ for the pointer operand in ‘(struct Extra **)&comp->pin + 4’ must not be NULL [-Waddress] 44 | return ExtraPtrOf(comp) ? 1 : 0; | ^ It only seems to be emitted when using the ?-operator. # gcc -v ... gcc version 12.1.1 20220507 (Red Hat 12.1.1-1) (GCC) # uname -a Linux fedora 5.17.6-300.fc36.x86_64 #1 SMP PREEMPT Mon May 9 15:47:11 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
The warning is correct but it should not be done. Simpele testcase: struct s{ int f; }; int g(struct s t){ return (t.f?&t.f : 0)? 1 : 0; } The problem is gcc did some optimizations before the warning and pushed the implicit != 0 into each arm of the ?; operator
GCC 12.3 is being released, retargeting bugs to GCC 12.4.
*** Bug 114306 has been marked as a duplicate of this bug. ***
So it turns out the change for ?: to warn for -Waddress was done on purpose. See PR 102967 . PR 102967 is about the wrong location for the warning and such but it was originally about the same type of expression. *** This bug has been marked as a duplicate of bug 102967 ***