diff options
author | Jason Merrill <jason@redhat.com> | 2020-02-04 14:21:59 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2020-02-04 14:49:19 -0500 |
commit | a1c9c9ff06ab15e697d5bac6ea6e5da2df840cf5 (patch) | |
tree | af34dc70a827bcd8d370e55e2834c5d90c5f8446 /gcc/cp/constexpr.c | |
parent | c422cec54a5495f6f42b80f35a11c5508fe8eec3 (diff) | |
download | gcc-a1c9c9ff06ab15e697d5bac6ea6e5da2df840cf5.zip gcc-a1c9c9ff06ab15e697d5bac6ea6e5da2df840cf5.tar.gz gcc-a1c9c9ff06ab15e697d5bac6ea6e5da2df840cf5.tar.bz2 |
c++: Fix ({ ... }) array mem-initializer.
Here, we were going down the wrong path in perform_member_init because of
the incorrect parens around the mem-initializer for the array. And then
cxx_eval_vec_init_1 didn't know what to do with a CONSTRUCTOR as the
initializer. The latter issue was a straightforward fix, but I also wanted
to fix us silently accepting the parens, which led to factoring out handling
of TREE_LIST and flexarrays. The latter led to adjusting the expected
behavior on flexary29.C: we should complain about the initializer, but not
complain about a missing initializer.
As I commented on PR 92812, in this process I noticed that we weren't
handling C++20 parenthesized aggregate initialization as a mem-initializer.
So my TREE_LIST handling includes a commented out section that should
probably be part of a future fix for that issue; with it uncommented we
continue to crash on the testcase in C++20 mode, but should instead complain
about the braced-init-list not being a valid initializer for an A.
PR c++/86917
* init.c (perform_member_init): Simplify.
* constexpr.c (cx_check_missing_mem_inits): Allow uninitialized
flexarray.
(cxx_eval_vec_init_1): Handle CONSTRUCTOR.
Diffstat (limited to 'gcc/cp/constexpr.c')
-rw-r--r-- | gcc/cp/constexpr.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 3962763..c35ec5a 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -826,7 +826,12 @@ cx_check_missing_mem_inits (tree ctype, tree body, bool complain) return true; continue; } - ftype = strip_array_types (TREE_TYPE (field)); + ftype = TREE_TYPE (field); + if (!ftype || !TYPE_P (ftype) || !COMPLETE_TYPE_P (ftype)) + /* A flexible array can't be intialized here, so don't complain + that it isn't. */ + continue; + ftype = strip_array_types (ftype); if (type_has_constexpr_default_constructor (ftype)) { /* It's OK to skip a member with a trivial constexpr ctor. @@ -3784,6 +3789,10 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init, unsigned HOST_WIDE_INT i; tsubst_flags_t complain = ctx->quiet ? tf_none : tf_warning_or_error; + if (init && TREE_CODE (init) == CONSTRUCTOR) + return cxx_eval_bare_aggregate (ctx, init, lval, + non_constant_p, overflow_p); + /* For the default constructor, build up a call to the default constructor of the element type. We only need to handle class types here, as for a constructor to be constexpr, all members must be |