public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/104082] New: Wdangling-pointer: 2 * false positive ?
@ 2022-01-18  8:37 dcb314 at hotmail dot com
  2022-01-18  8:44 ` [Bug c/104082] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: dcb314 at hotmail dot com @ 2022-01-18  8:37 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-18 16:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-18  8:37 [Bug c/104082] New: Wdangling-pointer: 2 * false positive ? dcb314 at hotmail dot com
2022-01-18  8:44 ` [Bug c/104082] " pinskia at gcc dot gnu.org
2022-01-18  9:00 ` [Bug tree-optimization/104082] " dcb314 at hotmail dot com
2022-01-18  9:35 ` rguenth at gcc dot gnu.org
2022-01-18 11:02 ` dcb314 at hotmail dot com
2022-01-18 16:49 ` msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).