Handle constexpr conversion from and then to the same type.
authorJason Merrill <jason@redhat.com>
Tue, 18 Jun 2019 16:08:17 +0000 (12:08 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 18 Jun 2019 16:08:17 +0000 (12:08 -0400)
* constexpr.c (cxx_eval_constant_expression): Handle conversion from
and then to the same type.

From-SVN: r272429

gcc/cp/ChangeLog
gcc/cp/constexpr.c

index eb795b8..4f26dc3 100644 (file)
@@ -1,5 +1,10 @@
 2019-06-18  Jason Merrill  <jason@redhat.com>
 
+       * constexpr.c (cxx_eval_constant_expression): Handle conversion from
+       and then to the same type.
+
+2019-06-18  Jason Merrill  <jason@redhat.com>
+
        * constexpr.c (unshare_constructor): Add MEM_STAT_DECL.
 
 2019-06-17  Jakub Jelinek  <jakub@redhat.com>
index 22901f8..0f68a0c 100644 (file)
@@ -5034,6 +5034,10 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
        if (*non_constant_p)
          return t;
        tree type = TREE_TYPE (t);
+
+       if (VOID_TYPE_P (type))
+         return void_node;
+
        if (TREE_CODE (op) == PTRMEM_CST
            && !TYPE_PTRMEM_P (type))
          op = cplus_expand_constant (op);
@@ -5094,14 +5098,18 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
             conversion.  */
          return fold (t);
 
+       tree sop;
+
        /* Handle an array's bounds having been deduced after we built
           the wrapping expression.  */
        if (same_type_ignoring_tlq_and_bounds_p (type, TREE_TYPE (op)))
          r = op;
+       else if (sop = tree_strip_nop_conversions (op),
+                sop != op && (same_type_ignoring_tlq_and_bounds_p
+                              (type, TREE_TYPE (sop))))
+         r = sop;
        else if (tcode == UNARY_PLUS_EXPR)
          r = fold_convert (TREE_TYPE (t), op);
-       else if (VOID_TYPE_P (type))
-         r = void_node;
        else
          r = fold_build1 (tcode, type, op);