From 02a8575c0cc6cc0004afaee095185775cd61f080 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 18 Jun 2019 12:08:17 -0400 Subject: [PATCH] Handle constexpr conversion from and then to the same type. * constexpr.c (cxx_eval_constant_expression): Handle conversion from and then to the same type. From-SVN: r272429 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/constexpr.c | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index eb795b82b31..4f26dc3423f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-06-18 Jason Merrill + + * constexpr.c (cxx_eval_constant_expression): Handle conversion from + and then to the same type. + 2019-06-18 Jason Merrill * constexpr.c (unshare_constructor): Add MEM_STAT_DECL. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 22901f811f1..0f68a0c9fca 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -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); -- 2.30.2