diff options
author | Marek Polacek <polacek@redhat.com> | 2020-02-19 15:59:33 -0500 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2020-02-26 10:33:18 -0500 |
commit | 38e1002657828150b2cda9f80c1f752184286e80 (patch) | |
tree | 848964a3def8a1c117965c14e08b2b68c378cbb8 /gcc/cp/init.c | |
parent | 8ce13842b50cbd2676f2e322995182af20df31fe (diff) | |
download | gcc-38e1002657828150b2cda9f80c1f752184286e80.zip gcc-38e1002657828150b2cda9f80c1f752184286e80.tar.gz gcc-38e1002657828150b2cda9f80c1f752184286e80.tar.bz2 |
c++: Fix value-init crash in template [PR93676]
Since <https://gcc.gnu.org/ml/gcc-patches/2015-02/msg00556.html> we
attempt to value-initialize in build_vec_init even when there's no
initializer but the type has a constexpr default constructor. But
build_value_init doesn't work in templates, and build_vec_init
creates a lot of garbage that would not be used anyway, so don't
call it in a template.
PR c++/93676 - value-init crash in template.
* init.c (build_new_1): Don't call build_vec_init in a template.
* g++.dg/cpp0x/nsdmi-template19.C: New test.
Diffstat (limited to 'gcc/cp/init.c')
-rw-r--r-- | gcc/cp/init.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/gcc/cp/init.c b/gcc/cp/init.c index d480660..61ed3aa 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -3511,13 +3511,17 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts, explicit_value_init_p = true; } - if (processing_template_decl && explicit_value_init_p) + if (processing_template_decl) { + /* Avoid an ICE when converting to a base in build_simple_base_path. + We'll throw this all away anyway, and build_new will create + a NEW_EXPR. */ + tree t = fold_convert (build_pointer_type (elt_type), data_addr); /* build_value_init doesn't work in templates, and we don't need the initializer anyway since we're going to throw it away and rebuild it at instantiation time, so just build up a single constructor call to get any appropriate diagnostics. */ - init_expr = cp_build_fold_indirect_ref (data_addr); + init_expr = cp_build_fold_indirect_ref (t); if (type_build_ctor_call (elt_type)) init_expr = build_special_member_call (init_expr, complete_ctor_identifier, |