diff options
author | Martin Sebor <msebor@redhat.com> | 2020-03-04 18:19:31 -0700 |
---|---|---|
committer | Martin Sebor <msebor@redhat.com> | 2020-03-04 18:19:31 -0700 |
commit | cb2409c60aeff498064346f85165531a3bbead14 (patch) | |
tree | d4339dd2f882ebf991d3047bd9549683abc233c1 /gcc/cp | |
parent | 547cdf8510a0096d5d6e4d54f0e3fe51d7b70e13 (diff) | |
download | gcc-cb2409c60aeff498064346f85165531a3bbead14.zip gcc-cb2409c60aeff498064346f85165531a3bbead14.tar.gz gcc-cb2409c60aeff498064346f85165531a3bbead14.tar.bz2 |
PR c++/90938 - Initializing array with {1} works but not {0}
gcc/cp/ChangeLog:
PR c++/90938
* tree.c (type_initializer_zero_p): Fail for structs initialized
with non-structs.
gcc/testsuite/ChangeLog:
PR c++/90938
* g++.dg/init/array55.C: New test.
* g++.dg/init/array56.C: New test.
* g++.dg/cpp2a/nontype-class33.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/tree.c | 10 |
2 files changed, 15 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 254e5a3..f01563e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2020-03-04 Martin Sebor <msebor@redhat.com> + + PR c++/90938 + * tree.c (type_initializer_zero_p): Fail for structs initialized + with non-structs. + 2020-03-04 Jason Merrill <jason@redhat.com> PR c++/90432 diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 3fc6287..a412345 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -5727,7 +5727,15 @@ type_initializer_zero_p (tree type, tree init) return TREE_CODE (init) != STRING_CST && initializer_zerop (init); if (TREE_CODE (init) != CONSTRUCTOR) - return initializer_zerop (init); + { + /* A class can only be initialized by a non-class type if it has + a ctor that converts from that type. Such classes are excluded + since their semantics are unknown. */ + if (RECORD_OR_UNION_TYPE_P (type) + && !RECORD_OR_UNION_TYPE_P (TREE_TYPE (init))) + return false; + return initializer_zerop (init); + } if (TREE_CODE (type) == ARRAY_TYPE) { |