On 3/2/23 16:24, Marek Polacek wrote:
On Wed, Mar 01, 2023 at 04:53:23PM -0500, Jason Merrill wrote:
@@ -13791,12 +13830,39 @@ std_pair_ref_ref_p (tree t)
        const int& y = (f(1), 42); // NULL_TREE
        const int& z = f(f(1)); // f(f(1))
-   EXPR is the initializer.  */
+   EXPR is the initializer.  If ARG_P is true, we're processing an argument
+   to a function; the point is to distinguish between, for example,
+
+     Ref::inner (&TARGET_EXPR <D.2839, F::foo (fm)>)
+
+   where we shouldn't warn, and
+
+     Ref::inner (&TARGET_EXPR <D.2908, F::foo (&TARGET_EXPR <...>)>)
+
+   where we should warn (Ref is a reference_like_class_p so we see through
+   it.  */
   static tree
-do_warn_dangling_reference (tree expr)
+do_warn_dangling_reference (tree expr, bool arg_p)
   {
     STRIP_NOPS (expr);
+  if (TREE_CODE (expr) == ADDR_EXPR)
+    expr = TREE_OPERAND (expr, 0);

I think if we move this here, we also need to check that expr before
STRIP_NOPS had REFERENCE_TYPE.  OK with that change.

Sorry but I don't think I can do that.  There can be CONVERT_EXPRs
that need to be stripped, whether arg_p or !arg_p.  For example, we can get
(const int *) f ((const int &) &TARGET_EXPR <D.2765, NON_LVALUE_EXPR <10>>)
for
const int& r5 = (42, f(10));

I meant that we only want to strip ADDR_EXPR if 'expr' at the start of the function had REFERENCE_TYPE, corresponding to

/* Check that this argument initializes a reference, except for the argument initializing the object of a member function. */
            if (!DECL_NONSTATIC_MEMBER_FUNCTION_P (fndecl)
                && !TYPE_REF_P (TREE_TYPE (arg)))
              continue;

above the code for stripping an ADDR_EXPR from an argument that your patch removes.

If the original expr is a pointer rather than a reference, we don't want to complain about it pointing to a temporary.

Jason

Reply via email to