public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109774] New: Spurious dangling reference warning in GCC 13 - another variant
@ 2023-05-08 15:19 minty.bobby at gmail dot com
  2023-05-09 13:21 ` [Bug c++/109774] template function causes Spurious dangling reference warning while non-template does not ppalka at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: minty.bobby at gmail dot com @ 2023-05-08 15:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109774
           Summary: Spurious dangling reference warning in GCC 13 -
                    another variant
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: minty.bobby at gmail dot com
  Target Milestone: ---

Created attachment 55021
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55021&action=edit
the function get() gives a spurious warning, but the very similar function
get2() does not

Similar to some of the other bug reports involving the new  dangling reference
warning, but here we have 2 very similar functions, and only one gives the
warning. Perhaps there is scope to tweak the heuristics to improve this case? 

In the attached file, the templated function get() gives a spurious warning,
but the very similar but non-template function get2() does not.

Note the reference passed in is of a different type to the reference that is
returned - I don't feel there should be confusion between them?

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

* [Bug c++/109774] template function causes Spurious dangling reference warning while non-template does not
  2023-05-08 15:19 [Bug c++/109774] New: Spurious dangling reference warning in GCC 13 - another variant minty.bobby at gmail dot com
@ 2023-05-09 13:21 ` ppalka at gcc dot gnu.org
  2023-05-10 20:57 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-05-09 13:21 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-05-09
             Status|UNCONFIRMED                 |NEW
                 CC|                            |mpolacek at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Thanks for the report, confirmed.

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

* [Bug c++/109774] template function causes Spurious dangling reference warning while non-template does not
  2023-05-08 15:19 [Bug c++/109774] New: Spurious dangling reference warning in GCC 13 - another variant minty.bobby at gmail dot com
  2023-05-09 13:21 ` [Bug c++/109774] template function causes Spurious dangling reference warning while non-template does not ppalka at gcc dot gnu.org
@ 2023-05-10 20:57 ` mpolacek at gcc dot gnu.org
  2023-05-16 19:40 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-05-10 20:57 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Here it comes down to

13900             || warning_suppressed_p (fndecl, OPT_Wdangling_reference)

in do_warn_dangling_reference.  So it's about the propagation of the
suppression bits.

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

* [Bug c++/109774] template function causes Spurious dangling reference warning while non-template does not
  2023-05-08 15:19 [Bug c++/109774] New: Spurious dangling reference warning in GCC 13 - another variant minty.bobby at gmail dot com
  2023-05-09 13:21 ` [Bug c++/109774] template function causes Spurious dangling reference warning while non-template does not ppalka at gcc dot gnu.org
  2023-05-10 20:57 ` mpolacek at gcc dot gnu.org
@ 2023-05-16 19:40 ` cvs-commit at gcc dot gnu.org
  2023-05-16 19:54 ` cvs-commit at gcc dot gnu.org
  2023-05-16 19:54 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-16 19:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:f25d2de17663a0132f9fe090dee39d3b1132067b

commit r14-919-gf25d2de17663a0132f9fe090dee39d3b1132067b
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue May 16 14:12:06 2023 -0400

    c++: -Wdangling-reference not suppressed in template [PR109774]

    In check_return_expr, we suppress the -Wdangling-reference warning when
    we're sure it would be a false positive.  It wasn't working in a
    template, though, because the suppress_warning call was never reached.

            PR c++/109774

    gcc/cp/ChangeLog:

            * typeck.cc (check_return_expr): In a template, return only after
            suppressing -Wdangling-reference.

    gcc/testsuite/ChangeLog:

            * g++.dg/warn/Wdangling-reference13.C: New test.

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

* [Bug c++/109774] template function causes Spurious dangling reference warning while non-template does not
  2023-05-08 15:19 [Bug c++/109774] New: Spurious dangling reference warning in GCC 13 - another variant minty.bobby at gmail dot com
                   ` (2 preceding siblings ...)
  2023-05-16 19:40 ` cvs-commit at gcc dot gnu.org
@ 2023-05-16 19:54 ` cvs-commit at gcc dot gnu.org
  2023-05-16 19:54 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-16 19:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:22741a09a8cbf8a360e99e530b016233dd705ce4

commit r13-7337-g22741a09a8cbf8a360e99e530b016233dd705ce4
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue May 16 14:12:06 2023 -0400

    c++: -Wdangling-reference not suppressed in template [PR109774]

    In check_return_expr, we suppress the -Wdangling-reference warning when
    we're sure it would be a false positive.  It wasn't working in a
    template, though, because the suppress_warning call was never reached.

            PR c++/109774

    gcc/cp/ChangeLog:

            * typeck.cc (check_return_expr): In a template, return only after
            suppressing -Wdangling-reference.

    gcc/testsuite/ChangeLog:

            * g++.dg/warn/Wdangling-reference13.C: New test.

    (cherry picked from commit f25d2de17663a0132f9fe090dee39d3b1132067b)

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

* [Bug c++/109774] template function causes Spurious dangling reference warning while non-template does not
  2023-05-08 15:19 [Bug c++/109774] New: Spurious dangling reference warning in GCC 13 - another variant minty.bobby at gmail dot com
                   ` (3 preceding siblings ...)
  2023-05-16 19:54 ` cvs-commit at gcc dot gnu.org
@ 2023-05-16 19:54 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-05-16 19:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2023-05-16 19:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-08 15:19 [Bug c++/109774] New: Spurious dangling reference warning in GCC 13 - another variant minty.bobby at gmail dot com
2023-05-09 13:21 ` [Bug c++/109774] template function causes Spurious dangling reference warning while non-template does not ppalka at gcc dot gnu.org
2023-05-10 20:57 ` mpolacek at gcc dot gnu.org
2023-05-16 19:40 ` cvs-commit at gcc dot gnu.org
2023-05-16 19:54 ` cvs-commit at gcc dot gnu.org
2023-05-16 19:54 ` mpolacek 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).