aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2019-08-01 23:45:36 +0000
committerMartin Sebor <msebor@redhat.com>2019-08-01 23:45:36 +0000
commit2f65414f43f5fe3fddea13f1c0995b45b01c6f81 (patch)
tree7c4a96774ea3cef422ba9596824ceb090bf0ff21 /gcc/cp/decl.c
parent6988a2ec402eb06621fe660227ae57838a3662a1 (diff)
PR c++/90947 - Simple lookup table of array of strings is miscompiled
gcc/cp/ChangeLog: PR c++/90947 * decl.c (reshape_init_array_1): Avoid truncating initializer lists containing string literals. gcc/testsuite/ChangeLog: PR c++/90947 * c-c++-common/array-1.c: New test. * g++.dg/abi/mangle73.C: New test. * g++.dg/cpp2a/nontype-class23.C: New test. * g++.dg/init/array53.C: New test. gcc/ChangeLog: PR c++/90947 * tree.c (type_initializer_zero_p): Define. * tree.h (type_initializer_zero_p): New function. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@273989 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r--gcc/cp/decl.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c8b9e3b8fb9..a1ab5ca8193 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5899,8 +5899,9 @@ reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
/* Pointers initialized to strings must be treated as non-zero
even if the string is empty. */
tree init_type = TREE_TYPE (elt_init);
- if ((POINTER_TYPE_P (elt_type) != POINTER_TYPE_P (init_type))
- || !initializer_zerop (elt_init))
+ if ((POINTER_TYPE_P (elt_type) != POINTER_TYPE_P (init_type)))
+ last_nonzero = index;
+ else if (!type_initializer_zero_p (elt_type, elt_init))
last_nonzero = index;
/* This can happen with an invalid initializer (c++/54501). */