https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104082
Bug ID: 104082 Summary: Wdangling-pointer: 2 * false positive ? Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: dcb314 at hotmail dot com Target Milestone: --- For this C++ code: $ more bug790.cc int *metricp; void s88() { int distance; metricp = &distance; } $ Does this with recent gcc trunk: $ /home/dcb/gcc/results/bin/gcc -c -O2 -D_FORTIFY_SOURCE=2 -Wall bug790.cc bug790.cc: In function ‘void s88()’: bug790.cc:4:11: warning: storing the address of local variable ‘distance’ in ‘metricp’ [-Wdangling-pointer=] 4 | metricp = &distance; | ~~~~~~~~^~~~~~~~~~~ bug790.cc:3:7: note: ‘distance’ declared here 3 | int distance; | ^~~~~~~~ bug790.cc:1:6: note: ‘metricp’ declared here 1 | int *metricp; | ^~~~~~~ bug790.cc:4:11: warning: storing the address of local variable ‘distance’ in ‘metricp’ [-Wdangling-pointer=] 4 | metricp = &distance; | ~~~~~~~~^~~~~~~~~~~ bug790.cc:3:7: note: ‘distance’ declared here 3 | int distance; | ^~~~~~~~ bug790.cc:1:6: note: ‘metricp’ declared here 1 | int *metricp; | ^~~~~~~ $ I've no idea why the warning is generated, the code looks legal to me and I've no idea why the warning is duplicated.