public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "romain.geissler at amadeus dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/108165] New: -Wdangling-reference false positive
Date: Sun, 18 Dec 2022 17:41:36 +0000	[thread overview]
Message-ID: <bug-108165-4@http.gcc.gnu.org/bugzilla/> (raw)

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);
      |                       ~^~~~~~~

             reply	other threads:[~2022-12-18 17:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-18 17:41 romain.geissler at amadeus dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-108165-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).