public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114909] New: False positive diagnostic from -Wdangling-reference
@ 2024-05-01 16:17 oleg at smolsky dot net
  2024-05-01 16:41 ` [Bug c++/114909] " mpolacek at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: oleg at smolsky dot net @ 2024-05-01 16:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114909
           Summary: False positive diagnostic from -Wdangling-reference
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: oleg at smolsky dot net
  Target Milestone: ---

struct string {
    string(const char *);
};

struct Json {
    int size() const;
};

const Json &fn1(const Json &obj, const string &key);

int Test1(const Json &arg)
{
    // warning: possibly dangling reference to a temporary
[-Wdangling-reference]
    const Json &jv = fn1(arg, "something"); 
    return jv.size();
}

const Json &fn2(const Json &obj);

int Test2(const Json &arg)
{
    // all good
    const Json &jv = fn2(arg);
    return jv.size();
}

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

* [Bug c++/114909] False positive diagnostic from -Wdangling-reference
  2024-05-01 16:17 [Bug c++/114909] New: False positive diagnostic from -Wdangling-reference oleg at smolsky dot net
@ 2024-05-01 16:41 ` mpolacek at gcc dot gnu.org
  2024-05-01 17:07 ` oleg at smolsky dot net
  2024-05-01 17:18 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-05-01 16:41 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
fn1 returns a reference and takes a temporary as an argument; we can't prove
that it doesn't return a reference to the temporary, so we warn.  Please add
[[gnu::no_dangling]] to fn1 to suppress the warning.

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

* [Bug c++/114909] False positive diagnostic from -Wdangling-reference
  2024-05-01 16:17 [Bug c++/114909] New: False positive diagnostic from -Wdangling-reference oleg at smolsky dot net
  2024-05-01 16:41 ` [Bug c++/114909] " mpolacek at gcc dot gnu.org
@ 2024-05-01 17:07 ` oleg at smolsky dot net
  2024-05-01 17:18 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: oleg at smolsky dot net @ 2024-05-01 17:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Oleg Smolsky <oleg at smolsky dot net> ---
It seems like an unreasonable stretch to connect a `string` temporary to the
returned `Json` reference. The types are not related and so that guess looks
overly aggressive...

The surgical workaround should work, thanks! I hope it does not generate a
Clang warning. Let me check that :)

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

* [Bug c++/114909] False positive diagnostic from -Wdangling-reference
  2024-05-01 16:17 [Bug c++/114909] New: False positive diagnostic from -Wdangling-reference oleg at smolsky dot net
  2024-05-01 16:41 ` [Bug c++/114909] " mpolacek at gcc dot gnu.org
  2024-05-01 17:07 ` oleg at smolsky dot net
@ 2024-05-01 17:18 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-01 17:18 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=110358
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
See discussion in PR 110358, PR 114220, PR 110213, and PR 109642 (and more).

*** This bug has been marked as a duplicate of bug 109642 ***

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

end of thread, other threads:[~2024-05-01 17:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-01 16:17 [Bug c++/114909] New: False positive diagnostic from -Wdangling-reference oleg at smolsky dot net
2024-05-01 16:41 ` [Bug c++/114909] " mpolacek at gcc dot gnu.org
2024-05-01 17:07 ` oleg at smolsky dot net
2024-05-01 17:18 ` pinskia 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).