]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Handle constexpr conversion from and then to the same type.
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 18 Jun 2019 16:08:17 +0000 (16:08 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 18 Jun 2019 16:08:17 +0000 (16:08 +0000)
* constexpr.c (cxx_eval_constant_expression): Handle conversion from
and then to the same type.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@272429 138bc75d-0d04-0410-961f-82ee72b054a4

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

index eb795b82b31a0a4a1b58e80ac6fee185c4014517..4f26dc3423f154d2c6f86f983abdd9820c832c7c 100644 (file)
@@ -1,3 +1,8 @@
+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.
index 22901f811f1680954e55fc2ff2afd1aa0d89e68b..0f68a0c9fcac73ba1b6a479336ee0f35da8d009a 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);