From b1a8b92f8f78536a00012e2e53a0d12ddbe6836d Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 28 Jan 2022 20:01:06 -0500 Subject: c++: Reject union std::initializer_list [PR102434] Weird things are going to happen if you define your std::initializer_list as a union. In this case, we crash in output_constructor_regular_field. Let's not allow such a definition in the first place. PR c++/102434 gcc/cp/ChangeLog: * class.cc (finish_struct): Don't allow union initializer_list. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist128.C: New test. --- gcc/cp/class.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gcc/cp/class.cc') diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc index 5db3722..6961557 100644 --- a/gcc/cp/class.cc +++ b/gcc/cp/class.cc @@ -7766,6 +7766,8 @@ finish_struct (tree t, tree attributes) ok = true; } } + /* It also cannot be a union. */ + ok &= NON_UNION_CLASS_TYPE_P (t); if (!ok) fatal_error (input_location, "definition of %qD does not match " "%<#include %>", TYPE_NAME (t)); -- cgit v1.1