The case of an initializer with side effects for a zero-length array seems
extremely unlikely, but we should still return the right type in that case.

Tested x86_64-pc-linux-gnu, applying to trunk.

        PR c++/101029

gcc/cp/ChangeLog:

        * init.c (build_vec_init): Preserve the type of base.
---
 gcc/cp/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 622d6e9d0c5..4bd942f3f74 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -4226,7 +4226,7 @@ build_vec_init (tree base, tree maxindex, tree init,
     {
       /* Shortcut zero element case to avoid unneeded constructor synthesis.  
*/
       if (init && TREE_SIDE_EFFECTS (init))
-       base = build2 (COMPOUND_EXPR, void_type_node, init, base);
+       base = build2 (COMPOUND_EXPR, ptype, init, base);
       return base;
     }
 

base-commit: 6816a44dfe1b5fa9414490a18a4aa723b6f38f18
-- 
2.27.0

Reply via email to