diff options
author | Jason Merrill <jason@redhat.com> | 2020-02-04 15:54:17 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2020-02-04 17:22:15 -0500 |
commit | 0712ea6313bc44f9ae8feb235c1b02c92cdd0527 (patch) | |
tree | 3aa6e9002bb84eff5d079942d90f2d4820928362 /gcc/cp/constexpr.c | |
parent | a1c9c9ff06ab15e697d5bac6ea6e5da2df840cf5 (diff) | |
download | gcc-0712ea6313bc44f9ae8feb235c1b02c92cdd0527.zip gcc-0712ea6313bc44f9ae8feb235c1b02c92cdd0527.tar.gz gcc-0712ea6313bc44f9ae8feb235c1b02c92cdd0527.tar.bz2 |
c++: Fix constexpr vs. omitted aggregate init.
Value-initialization is importantly different from {}-initialization for
this testcase, where the former calls the deleted S constructor and the
latter initializes S happily.
PR c++/90951
* constexpr.c (cxx_eval_array_reference): {}-initialize missing
elements instead of value-initializing them.
Diffstat (limited to 'gcc/cp/constexpr.c')
-rw-r--r-- | gcc/cp/constexpr.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index c35ec5a..8a02c6e 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -3324,8 +3324,16 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t, } /* If it's within the array bounds but doesn't have an explicit - initializer, it's value-initialized. */ - tree val = build_value_init (elem_type, tf_warning_or_error); + initializer, it's initialized from {}. But use build_value_init + directly for non-aggregates to avoid creating a garbage CONSTRUCTOR. */ + tree val; + if (CP_AGGREGATE_TYPE_P (elem_type)) + { + tree empty_ctor = build_constructor (init_list_type_node, NULL); + val = digest_init (elem_type, empty_ctor, tf_warning_or_error); + } + else + val = build_value_init (elem_type, tf_warning_or_error); return cxx_eval_constant_expression (ctx, val, lval, non_constant_p, overflow_p); } |