From 56da7fe60998b5072a48e832cc28e85a0bc245ae Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 10 Sep 2017 09:11:40 +0000 Subject: [PATCH] A partially initialized variable isn't constant. * constexpr.c (reduced_constant_expression_p): If CONSTRUCTOR_NO_IMPLICIT_ZERO, check that all fields are initialized. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@251948 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/constexpr.c | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fa3e00889c3..8395862620b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2017-09-09 Jason Merrill + + * constexpr.c (reduced_constant_expression_p): If + CONSTRUCTOR_NO_IMPLICIT_ZERO, check that all fields are initialized. + 2017-09-09 Eric Botcazou PR bootstrap/81926 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index a5692fb3b3a..2d2f3b854ba 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -1732,15 +1732,30 @@ reduced_constant_expression_p (tree t) case CONSTRUCTOR: /* And we need to handle PTRMEM_CST wrapped in a CONSTRUCTOR. */ - tree elt; unsigned HOST_WIDE_INT idx; - FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t), idx, elt) + tree idx, val, field; unsigned HOST_WIDE_INT i; + if (CONSTRUCTOR_NO_IMPLICIT_ZERO (t)) + field = next_initializable_field (TYPE_FIELDS (TREE_TYPE (t))); + else + field = NULL_TREE; + FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), i, idx, val) { - if (!elt) + if (!val) /* We're in the middle of initializing this element. */ return false; - if (!reduced_constant_expression_p (elt)) + if (!reduced_constant_expression_p (val)) return false; + if (field) + { + if (idx != field) + return false; + field = next_initializable_field (DECL_CHAIN (field)); + } } + if (field) + return false; + else if (CONSTRUCTOR_NO_IMPLICIT_ZERO (t)) + /* All the fields are initialized. */ + CONSTRUCTOR_NO_IMPLICIT_ZERO (t) = false; return true; default: -- 2.11.4.GIT