https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122896
--- Comment #2 from Alejandro Colomar <[email protected]> --- (In reply to Andrew Pinski from comment #1) > Removing: > ``` > if (x) *i = 42; > if (1) *s = 7; > ``` > > And the warning shows up. I don't know why or understand why. > > Confirmed. I've been experimenting after your comment, and it seems we only need to remove the one with 'x' to trigger it. The one with '1' seems independent. alx@devuan:~/tmp$ cat f.c #include <stddef.h> void f(int x, long *l, int *i, short *s) { if (l == NULL) l = &(long){0}; if (i == NULL) i = &(int){0}; if (s == NULL) s = &(short){0}; *l = 7; //if (x) *s = 7; if (1) *s = 7; } alx@devuan:~/tmp$ gcc -S -Wdangling-pointer=1 f.c alx@devuan:~/tmp$ gcc -S -Wdangling-pointer=2 f.c f.c: In function ‘f’: f.c:13:12: warning: dangling pointer ‘l’ to an unnamed temporary may be used [-Wdangling-pointer=] 13 | *l = 7; | ~~~^~~ f.c:7:28: note: unnamed temporary defined here 7 | l = &(long){0}; | ^ f.c:15:19: warning: dangling pointer ‘s’ to an unnamed temporary may be used [-Wdangling-pointer=] 15 | if (1) *s = 7; | ~~~^~~ f.c:11:29: note: unnamed temporary defined here 11 | s = &(short){0}; | ^ alx@devuan:~/tmp$ vi f.c alx@devuan:~/tmp$ gcc -S -Wdangling-pointer=1 f.c alx@devuan:~/tmp$ gcc -S -Wdangling-pointer=2 f.c f.c: In function ‘f’: f.c:13:12: warning: dangling pointer ‘l’ to an unnamed temporary may be used [-Wdangling-pointer=] 13 | *l = 7; | ~~~^~~ f.c:7:28: note: unnamed temporary defined here 7 | l = &(long){0}; | ^
