diff options
author | Marek Polacek <polacek@redhat.com> | 2024-09-05 16:45:32 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2024-09-27 16:33:07 -0400 |
commit | 96e0370f4daef29b918aafcff68c7f5e4ef397fd (patch) | |
tree | a1cea64073abcd291d203a4071f0a86ecd2e6579 /gcc/cp | |
parent | c580b8a2b59208efc687e2b706e3a40225167854 (diff) | |
download | gcc-96e0370f4daef29b918aafcff68c7f5e4ef397fd.zip gcc-96e0370f4daef29b918aafcff68c7f5e4ef397fd.tar.gz gcc-96e0370f4daef29b918aafcff68c7f5e4ef397fd.tar.bz2 |
c++: ICE with structured bindings and m-d array [PR102594]
We ICE in decay_conversion with this test:
struct S {
S() {}
};
S arr[1][1];
auto [m](arr3);
But not when the last line is:
auto [n] = arr3;
Therefore the difference is between copy- and direct-init. In
particular, in build_vec_init we have:
if (direct_init)
from = build_tree_list (NULL_TREE, from);
and then we call build_vec_init again with init==from. Then
decay_conversion gets the TREE_LIST and it crashes.
build_aggr_init has:
/* Wrap the initializer in a CONSTRUCTOR so that build_vec_init
recognizes it as direct-initialization. */
init = build_constructor_single (init_list_type_node,
NULL_TREE, init);
CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
so I propose to do the same in build_vec_init.
PR c++/102594
gcc/cp/ChangeLog:
* init.cc (build_vec_init): Build up a CONSTRUCTOR to signal
direct-initialization rather than a TREE_LIST.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1z/decomp61.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/init.cc | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index be7fdb4..f785015 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -4958,7 +4958,13 @@ build_vec_init (tree base, tree maxindex, tree init, if (xvalue) from = move (from); if (direct_init) - from = build_tree_list (NULL_TREE, from); + { + /* Wrap the initializer in a CONSTRUCTOR so that + build_vec_init recognizes it as direct-initialization. */ + from = build_constructor_single (init_list_type_node, + NULL_TREE, from); + CONSTRUCTOR_IS_DIRECT_INIT (from) = true; + } } else from = NULL_TREE; |