aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2022-03-17 14:39:37 -0400
committerMarek Polacek <polacek@redhat.com>2022-03-24 16:59:57 -0400
commit9fdac7e16c940fb6264e6ddaf99c761f1a64a054 (patch)
tree33fae8fdc94ade66fe5fc55a1204b17dfbeb4159 /gcc/cp
parent346ab5a54a831ad9c78afcbd8dfe98e0e07e3070 (diff)
downloadgcc-9fdac7e16c940fb6264e6ddaf99c761f1a64a054.zip
gcc-9fdac7e16c940fb6264e6ddaf99c761f1a64a054.tar.gz
gcc-9fdac7e16c940fb6264e6ddaf99c761f1a64a054.tar.bz2
c++: ICE with template code in constexpr [PR104284]
Since r9-6073 cxx_eval_store_expression preevaluates the value to be stored, and that revealed a crash where a template code (here, code=IMPLICIT_CONV_EXPR) leaks into cxx_eval*. It happens because we're performing build_vec_init while processing a template, which calls get_temp_regvar which creates an INIT_EXPR. This INIT_EXPR's RHS contains an rvalue conversion so we create an IMPLICIT_CONV_EXPR. Its operand is not type-dependent and the whole INIT_EXPR is not type-dependent. So we call build_non_dependent_expr which, with -fchecking=2, calls fold_non_dependent_expr. At this point the expression still has an IMPLICIT_CONV_EXPR, which ought to be handled in instantiate_non_dependent_expr_internal. However, tsubst_copy_and_build doesn't handle INIT_EXPR; it will just call tsubst_copy which does nothing when args is null. So we fail to replace the IMPLICIT_CONV_EXPR and ICE. The problem is that we call build_vec_init in a template in the first place. We can avoid doing so by checking p_t_d before calling build_aggr_init in check_initializer. PR c++/104284 gcc/cp/ChangeLog: * decl.cc (check_initializer): Don't call build_aggr_init in a template. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/constexpr-104284-1.C: New test. * g++.dg/cpp1y/constexpr-104284-2.C: New test. * g++.dg/cpp1y/constexpr-104284-3.C: New test. * g++.dg/cpp1y/constexpr-104284-4.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/decl.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 68741bbf..69f60a6 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -7332,6 +7332,10 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
&& !(init && BRACE_ENCLOSED_INITIALIZER_P (init)
&& CP_AGGREGATE_TYPE_P (type)
&& (CLASS_TYPE_P (type)
+ /* The call to build_aggr_init below could end up
+ calling build_vec_init, which may break when we
+ are processing a template. */
+ || processing_template_decl
|| !TYPE_NEEDS_CONSTRUCTING (type)
|| type_has_extended_temps (type))))
|| (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))