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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-11-01
                 CC|                            |mpolacek at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot 
gnu.org
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I figure this warning is a false positive since "const int &attribute" refers
to one of the int elements of the vector v, not to a temporary object.

I think the warning should probably be disabled for operator*, since that
returns a reference but doesn't return its parameter:

      reference
      operator*() const _GLIBCXX_NOEXCEPT
      { return *_M_current; }

Patch:

--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -13467,7 +13467,11 @@ do_warn_dangling_reference (tree expr)
           can be e.g.
         const int& z = std::min({1, 2, 3, 4, 5, 6, 7});
           which doesn't dangle: std::min here returns an int.  */
-       || !TYPE_REF_OBJ_P (TREE_TYPE (TREE_TYPE (fndecl))))
+       || !TYPE_REF_OBJ_P (TREE_TYPE (TREE_TYPE (fndecl)))
+       /* XXX */
+       || (DECL_NONSTATIC_MEMBER_FUNCTION_P (fndecl)
+       && DECL_OVERLOADED_OPERATOR_P (fndecl)
+       && DECL_OVERLOADED_OPERATOR_IS (fndecl, INDIRECT_REF)))
      return NULL_TREE;

    /* Here we're looking to see if any of the arguments is a temporary

Reply via email to