c++: partially initialized constexpr array [PR99700]
authorPatrick Palka <ppalka@redhat.com>
Fri, 16 Apr 2021 13:24:46 +0000 (09:24 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 16 Apr 2021 13:24:46 +0000 (09:24 -0400)
commitbaf05d54dc919c968d12de9d049e36e5bac10dec
tree27466678b6db6aec3db06272c99efde1b6a2b651
parent47f42744f6e10ad41db926d739306e6f237fd3ac
c++: partially initialized constexpr array [PR99700]

Here, reduced_constant_expression_p is incorrectly returning true for a
partially initialized array CONSTRUCTOR (in C++20 mode) because when the
CONSTRUCTOR_NO_CLEARING flag is set, the predicate doesn't check that
the CONSTRUCTOR spans the entire array like it does for class CONSTRUCTORS.
This patch adds a dedicated loop for the array case that simultaneously
verifies the CONSTRUCTOR spans the entire array and is made up of valid
constant expressions.

gcc/cp/ChangeLog:

PR c++/99700
* constexpr.c (reduced_constant_expression_p): For array
CONSTRUCTORs, use a dedicated loop that additionally verifies
the CONSTRUCTOR spans the entire array.

gcc/testsuite/ChangeLog:

PR c++/99700
* g++.dg/cpp2a/constexpr-init21.C: New test.
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp2a/constexpr-init21.C [new file with mode: 0644]