public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108165] New: -Wdangling-reference false positive
@ 2022-12-18 17:41 romain.geissler at amadeus dot com
  2022-12-18 17:46 ` [Bug c++/108165] " pinskia at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: romain.geissler at amadeus dot com @ 2022-12-18 17:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108165

            Bug ID: 108165
           Summary: -Wdangling-reference false positive
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: romain.geissler at amadeus dot com
  Target Milestone: ---

Hi,

The following snippet issues a wrong -Wdangling-reference warning when compiled
with -Wall with current gcc trunk:

<<END_OF_FILE
struct A {};

struct B
{
    B(int) {}
};

const A& f(const A& a, const B&) {
    return a;
}

const A& g(const A& a) {
    const A& result = f(a, 42);

    return result;
}
END_OF_FILE

The warning is:

<source>: In function 'const A& g(const A&)':
<source>:13:14: warning: possibly dangling reference to a temporary
[-Wdangling-reference]
   13 |     const A& result = f(a, 42);
      |              ^~~~~~
<source>:13:24: note: the temporary was destroyed at the end of the full
expression 'f((* & a), B(42))'
   13 |     const A& result = f(a, 42);
      |                       ~^~~~~~~
ASM generation compiler returned: 0
<source>: In function 'const A& g(const A&)':
<source>:13:14: warning: possibly dangling reference to a temporary
[-Wdangling-reference]
   13 |     const A& result = f(a, 42);
      |              ^~~~~~
<source>:13:24: note: the temporary was destroyed at the end of the full
expression 'f((* & a), B(42))'
   13 |     const A& result = f(a, 42);
      |                       ~^~~~~~~

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

end of thread, other threads:[~2023-04-18  0:55 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-18 17:41 [Bug c++/108165] New: -Wdangling-reference false positive romain.geissler at amadeus dot com
2022-12-18 17:46 ` [Bug c++/108165] " pinskia at gcc dot gnu.org
2022-12-18 17:47 ` pinskia at gcc dot gnu.org
2022-12-18 18:06 ` romain.geissler at amadeus dot com
2022-12-19  8:41 ` marxin at gcc dot gnu.org
2022-12-19 13:31 ` redi at gcc dot gnu.org
2023-02-01 18:04 ` mpolacek at gcc dot gnu.org
2023-02-01 18:14 ` jakub at gcc dot gnu.org
2023-02-01 18:20 ` mpolacek at gcc dot gnu.org
2023-02-01 20:40 ` mpolacek at gcc dot gnu.org
2023-02-01 21:55 ` mpolacek at gcc dot gnu.org
2023-02-28  7:32 ` marxin at gcc dot gnu.org
2023-02-28 14:53 ` mpolacek at gcc dot gnu.org
2023-03-02  8:30 ` marxin at gcc dot gnu.org
2023-03-02 16:30 ` mpolacek at gcc dot gnu.org
2023-03-03  7:35 ` marxin at gcc dot gnu.org
2023-03-07 16:14 ` mpolacek at gcc dot gnu.org
2023-04-18  0:55 ` mrsam@courier-mta.com

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).