From 49b5925f0251cc30e510b374700c50dc99ce3891 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 29 Jul 2016 10:03:26 -0400 Subject: [PATCH] PR c++/72457 - ICE with list-value-initialized base. * init.c (expand_aggr_init_1): Only handle value-init of bases. * constexpr.c (build_data_member_initialization): Handle multiple initializers for the same field. From-SVN: r238867 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/constexpr.c | 7 ++++++- gcc/cp/init.c | 6 +++--- gcc/testsuite/g++.dg/cpp0x/constexpr-list1.C | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-list1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index cf692c9fbc6..62c6e53b99a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2016-07-29 Jason Merrill + + PR c++/72457 + * init.c (expand_aggr_init_1): Only handle value-init of bases. + * constexpr.c (build_data_member_initialization): Handle multiple + initializers for the same field. + 2016-07-28 Paolo Carlini PR c++/71665 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 6bcb41ae825..58716892f71 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -391,7 +391,12 @@ build_data_member_initialization (tree t, vec **vec) gcc_assert (TREE_TYPE (member) == vtbl_ptr_type_node); } - CONSTRUCTOR_APPEND_ELT (*vec, member, init); + /* Value-initialization can produce multiple initializers for the + same field; use the last one. */ + if (!vec_safe_is_empty (*vec) && (*vec)->last().index == member) + (*vec)->last().value = init; + else + CONSTRUCTOR_APPEND_ELT (*vec, member, init); return true; } diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 63622635983..1a5766a42b7 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1818,9 +1818,9 @@ expand_aggr_init_1 (tree binfo, tree true_exp, tree exp, tree init, int flags, } /* List-initialization from {} becomes value-initialization for non-aggregate - classes with default constructors. Handle this here so protected access - works. */ - if (init && TREE_CODE (init) == TREE_LIST) + classes with default constructors. Handle this here when we're + initializing a base, so protected access works. */ + if (exp != true_exp && init && TREE_CODE (init) == TREE_LIST) { tree elt = TREE_VALUE (init); if (DIRECT_LIST_INIT_P (elt) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-list1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-list1.C new file mode 100644 index 00000000000..f831a112cc9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-list1.C @@ -0,0 +1,15 @@ +// PR c++/72457 +// { dg-do compile { target c++11 } } + +struct A { + int i; + constexpr A(): i(0) {} +}; + +struct B: A { }; + +struct C +{ + B b; + constexpr C() : b{} {} +}; -- 2.30.2