[Bug c++/111607] False positive -Wdangling-reference
mpolacek at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jan 18 22:02:43 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111607
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
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=113256
Last reconfirmed| |2024-01-18
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Thanks for the report. I suppose we should not warn when the argument is a
lambda type. This might also fix bug 113256.
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -14123,7 +14123,8 @@ do_warn_dangling_reference (tree expr, bool arg_p)
tree e = expr;
while (handled_component_p (e))
e = TREE_OPERAND (e, 0);
- if (!reference_like_class_p (TREE_TYPE (e)))
+ if (!reference_like_class_p (TREE_TYPE (e))
+ && !LAMBDA_TYPE_P (TREE_TYPE (e)))
return expr;
}
@@ -14180,10 +14181,10 @@ do_warn_dangling_reference (tree expr, bool arg_p)
initializing this reference parameter. */
if (do_warn_dangling_reference (arg, /*arg_p=*/true))
return expr;
- /* Don't warn about member function like:
+ /* Don't warn about member functions like:
std::any a(...);
S& s = a.emplace<S>({0}, 0);
- which constructs a new object and returns a reference to it, but
+ which construct a new object and return a reference to it, but
we still want to detect:
struct S { const S& self () { return *this; } };
const S& s = S().self();
More information about the Gcc-bugs
mailing list