public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109640] New: Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference
@ 2023-04-26 23:24 ed at catmur dot uk
2023-04-26 23:40 ` [Bug c++/109640] " pinskia at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: ed at catmur dot uk @ 2023-04-26 23:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109640
Bug ID: 109640
Summary: Spurious Wdangling-reference for argument to temporary
lambda cast to rvalue reference
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ed at catmur dot uk
Target Milestone: ---
bool b() {
int a;
int&& i = [](int& r) -> int&& { return static_cast<int&&>(r); }(a);
auto const l = [](int& r) -> int&& { return static_cast<int&&>(r); };
int&& j = l(a);
return &i == &j;
}
<source>: In function 'bool b()':
<source>:3:11: warning: possibly dangling reference to a temporary
[-Wdangling-reference]
3 | int&& i = [](int& r) -> int&& { return static_cast<int&&>(r); }(a);
| ^
<source>:3:68: note: the temporary was destroyed at the end of the full
expression '<lambda closure
object>b()::<lambda(int&)>().b()::<lambda(int&)>(a)'
3 | int&& i = [](int& r) -> int&& { return static_cast<int&&>(r); }(a);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
The heuristic appears to be confused by the lambda itself being a temporary,
even though it is captureless.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109640] Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference
2023-04-26 23:24 [Bug c++/109640] New: Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference ed at catmur dot uk
@ 2023-04-26 23:40 ` pinskia at gcc dot gnu.org
2023-04-26 23:59 ` ed at catmur dot uk
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-26 23:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109640
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase:
```
struct f{};
int &&ffa(const f&, int &r) { return static_cast<int&&>(r); }
void b() {
int a;
int&& i = ffa(f{}, a);
i = 1;
}
```
Should see f{} is an empty struct which is exactly the same as the lambda here.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109640] Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference
2023-04-26 23:24 [Bug c++/109640] New: Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference ed at catmur dot uk
2023-04-26 23:40 ` [Bug c++/109640] " pinskia at gcc dot gnu.org
@ 2023-04-26 23:59 ` ed at catmur dot uk
2023-04-27 15:54 ` mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: ed at catmur dot uk @ 2023-04-26 23:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109640
--- Comment #2 from Ed Catmur <ed at catmur dot uk> ---
Ah, so this is Bug 108165? That's a shame, we use (temporary) lambdas
extensively so I think we'd have to disable the warning entirely.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109640] Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference
2023-04-26 23:24 [Bug c++/109640] New: Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference ed at catmur dot uk
2023-04-26 23:40 ` [Bug c++/109640] " pinskia at gcc dot gnu.org
2023-04-26 23:59 ` ed at catmur dot uk
@ 2023-04-27 15:54 ` mpolacek at gcc dot gnu.org
2023-05-02 19:49 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-04-27 15:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109640
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
We could probably disable the warning when the temporary is of empty class
type?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109640] Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference
2023-04-26 23:24 [Bug c++/109640] New: Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference ed at catmur dot uk
` (2 preceding siblings ...)
2023-04-27 15:54 ` mpolacek at gcc dot gnu.org
@ 2023-05-02 19:49 ` cvs-commit at gcc dot gnu.org
2024-01-18 23:05 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-02 19:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109640
--- 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:6b927b1297e66e26e62e722bf15c921dcbbd25b9
commit r13-7276-g6b927b1297e66e26e62e722bf15c921dcbbd25b9
Author: Marek Polacek <polacek@redhat.com>
Date: Tue May 2 15:48:40 2023 -0400
c++: Move -Wdangling-reference to -Wextra [PR109642]
Sadly, -Wdangling-reference generates false positives for std::span-like
user classes, and it seems imprudent to attempt to improve the heuristic
in GCC 13. Let's move the warning to -Wextra, that will hopefully
reduce the number of false positives the users have been seeing with 13.
I'm leaving the warning in -Wall in 14 where I think I can write code
to detect std::span-like classes.
PR c++/109642
PR c++/109640
PR c++/109671
gcc/c-family/ChangeLog:
* c.opt (Wdangling-reference): Move from -Wall to -Wextra.
gcc/ChangeLog:
* doc/invoke.texi: Document that -Wdangling-reference is
enabled by -Wextra.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109640] Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference
2023-04-26 23:24 [Bug c++/109640] New: Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference ed at catmur dot uk
` (3 preceding siblings ...)
2023-05-02 19:49 ` cvs-commit at gcc dot gnu.org
@ 2024-01-18 23:05 ` mpolacek at gcc dot gnu.org
2024-01-23 21:36 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-18 23:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109640
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Last reconfirmed| |2024-01-18
Ever confirmed|0 |1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109640] Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference
2023-04-26 23:24 [Bug c++/109640] New: Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference ed at catmur dot uk
` (4 preceding siblings ...)
2024-01-18 23:05 ` mpolacek at gcc dot gnu.org
@ 2024-01-23 21:36 ` cvs-commit at gcc dot gnu.org
2024-01-23 22:35 ` mpolacek at gcc dot gnu.org
2024-01-30 18:24 ` cvs-commit at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-23 21:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109640
--- Comment #5 from GCC 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:9010fdba68063beccfbab0aa9ec8739f232ca2f4
commit r14-8375-g9010fdba68063beccfbab0aa9ec8739f232ca2f4
Author: Marek Polacek <polacek@redhat.com>
Date: Fri Jan 19 13:59:41 2024 -0500
c++: -Wdangling-reference and lambda false warning [PR109640]
-Wdangling-reference checks if a function receives a temporary as its
argument, and only warns if any of the arguments was a temporary. But
we should not warn when the temporary represents a lambda or we generate
false positives as in the attached testcases.
PR c++/113256
PR c++/111607
PR c++/109640
gcc/cp/ChangeLog:
* call.cc (do_warn_dangling_reference): Don't warn if the temporary
is of lambda type.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wdangling-reference14.C: New test.
* g++.dg/warn/Wdangling-reference15.C: New test.
* g++.dg/warn/Wdangling-reference16.C: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109640] Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference
2023-04-26 23:24 [Bug c++/109640] New: Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference ed at catmur dot uk
` (5 preceding siblings ...)
2024-01-23 21:36 ` cvs-commit at gcc dot gnu.org
@ 2024-01-23 22:35 ` mpolacek at gcc dot gnu.org
2024-01-30 18:24 ` cvs-commit at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-23 22:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109640
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Should be fixed.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109640] Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference
2023-04-26 23:24 [Bug c++/109640] New: Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference ed at catmur dot uk
` (6 preceding siblings ...)
2024-01-23 22:35 ` mpolacek at gcc dot gnu.org
@ 2024-01-30 18:24 ` cvs-commit at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-30 18:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109640
--- Comment #7 from GCC 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:f2061b2a9641c2228d4e2d86f19532ad7e93d627
commit r14-8636-gf2061b2a9641c2228d4e2d86f19532ad7e93d627
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Jan 25 12:08:14 2024 -0500
c++: avoid -Wdangling-reference for std::span-like classes [PR110358]
Real-world experience shows that -Wdangling-reference triggers for
user-defined std::span-like classes a lot. We can easily avoid that
by considering classes like
template<typename T>
struct Span {
T* data_;
std::size len_;
};
to be std::span-like, and not warning for them. Unlike the previous
patch, this one considers a non-union class template that has a pointer
data member and a trivial destructor as std::span-like.
PR c++/110358
PR c++/109640
gcc/cp/ChangeLog:
* call.cc (reference_like_class_p): Don't warn for std::span-like
classes.
gcc/ChangeLog:
* doc/invoke.texi: Update -Wdangling-reference description.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wdangling-reference18.C: New test.
* g++.dg/warn/Wdangling-reference19.C: New test.
* g++.dg/warn/Wdangling-reference20.C: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-01-30 18:24 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-26 23:24 [Bug c++/109640] New: Spurious Wdangling-reference for argument to temporary lambda cast to rvalue reference ed at catmur dot uk
2023-04-26 23:40 ` [Bug c++/109640] " pinskia at gcc dot gnu.org
2023-04-26 23:59 ` ed at catmur dot uk
2023-04-27 15:54 ` mpolacek at gcc dot gnu.org
2023-05-02 19:49 ` cvs-commit at gcc dot gnu.org
2024-01-18 23:05 ` mpolacek at gcc dot gnu.org
2024-01-23 21:36 ` cvs-commit at gcc dot gnu.org
2024-01-23 22:35 ` mpolacek at gcc dot gnu.org
2024-01-30 18:24 ` cvs-commit 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).