diff options
author | Jakub Jelinek <jakub@redhat.com> | 2025-01-15 08:53:13 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2025-01-15 08:59:46 +0100 |
commit | 64828272cde415bf2d7222eec87147ba84980f3d (patch) | |
tree | 2f7e1a47e29082fd89ea4cf63a4d6d094797333e /gcc/testsuite/g++.dg/cpp0x | |
parent | f263f2d525eb9a1b60c2a356eb64262819b6bab0 (diff) | |
download | gcc-64828272cde415bf2d7222eec87147ba84980f3d.zip gcc-64828272cde415bf2d7222eec87147ba84980f3d.tar.gz gcc-64828272cde415bf2d7222eec87147ba84980f3d.tar.bz2 |
c++: Fix up maybe_init_list_as_array for RAW_DATA_CST [PR118124]
The previous patch made me look around some more and I found
maybe_init_list_as_array doesn't handle RAW_DATA_CSTs correctly either,
while the RAW_DATA_CST is properly split during finish_compound_literal,
it was using CONSTRUCTOR_NELTS as the size of the arrays, which is wrong,
RAW_DATA_CST could stand for far more initializers.
2025-01-15 Jakub Jelinek <jakub@redhat.com>
PR c++/118124
* cp-tree.h (build_array_of_n_type): Change second argument type
from int to unsigned HOST_WIDE_INT.
* tree.cc (build_array_of_n_type): Likewise.
* call.cc (count_ctor_elements): New function.
(maybe_init_list_as_array): Use it instead of CONSTRUCTOR_NELTS.
(convert_like_internal): Use length from init's type instead of
len when handling the maybe_init_list_as_array case.
* g++.dg/cpp0x/initlist-opt5.C: New test.
Diffstat (limited to 'gcc/testsuite/g++.dg/cpp0x')
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/initlist-opt5.C | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-opt5.C b/gcc/testsuite/g++.dg/cpp0x/initlist-opt5.C new file mode 100644 index 0000000..65a1fd6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-opt5.C @@ -0,0 +1,23 @@ +// PR c++/118124 +// { dg-do compile { target c++11 } } +// { dg-options "-O2" } + +namespace std { +template <class T> struct initializer_list { +private: + const T *_M_array; + decltype (sizeof 0) _M_len; +}; +} +struct B { + B (int); +}; +struct A { + A (std::initializer_list<B>); +}; +A a { 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, + 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, + 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5 }; |