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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2019-03-18
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org,
                   |                            |mpolacek at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Guess we also want to improve the -Wreturn-local-addr warning too.
Unfortunately:
--- gcc/cp/typeck.c.jj  2019-03-15 18:49:44.266307154 +0100
+++ gcc/cp/typeck.c     2019-03-18 18:24:33.791604856 +0100
@@ -9194,6 +9194,10 @@ maybe_warn_about_returning_address_of_lo
       else if (CONVERT_EXPR_P (whats_returned)
               || TREE_CODE (whats_returned) == NON_LVALUE_EXPR)
        whats_returned = TREE_OPERAND (whats_returned, 0);
+      else if (VAR_P (whats_returned)
+              && DECL_INITIAL (whats_returned)
+              && TYPE_REF_P (TREE_TYPE (whats_returned)))
+       whats_returned = DECL_INITIAL (whats_returned);
       else
        break;
     }
doesn't handle it, because for some reason we don't have DECL_INITIAL for the
reference, initialize it by a separate stmt.

Another example of the need to track variable lifetime during constexpr
evaluation is:
constexpr const int &
foo ()
{
  const int *p = nullptr;
  {
    const int r = 2;
    p = &r;
  }
  return *p;
}

constexpr int a = foo ();

Reply via email to