[Bug c++/125989] [C++29] P2287R6, Designated-initializers for Base Classes
"cvs-commit at gcc dot gnu.org via Gcc-bugs" <[email protected]> Thu, 06 Aug 2026 08:56:27 +0000
| Newsgroups | gmane.comp.gcc.bugs |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125989 --- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:d609ca7423dc3bae4b971a16303129d95512acac commit r17-3010-gd609ca7423dc3bae4b971a16303129d95512acac Author: Jakub Jelinek <[email protected]> Date: Thu Aug 6 10:51:44 2026 +0200 c++: implement C++29 P2287R6 - Designated-initializers for Base Classes [PR125989] The following patch implements the C++29 P2287R6 Designated-initializers for Base Classes paper. One change is during parsing, to match the new designated-initializer-list grammar, the patch allows non-designated clauses followed by designated clauses for C++29 or for C++20 to C++26 as pedwarned extension (but rejects designated followed by non-designated and also when using GNU style [0] = designators non-designated by designated with that GNU array style, while the grammar allows now in theory { 1, 2, [3] = 3, [4] = 4 } in theory I think it is undesirable to allow that mixing, the designated after non-designated has been added solely for base classes and arrays don't have those). Another change is in the if (first_desig && cxx_dialect >= cxx20) hunk, to reject non-designated clause which doesn't appertain to base class followed by designated clause. Yet another change is the lookup_member as fallback to get_class_binding, but according to the paper it shouldn't replace it, even if there is ambiguity, if the designator names a NSDM of current class, that should be what is used, only if it is an ambiguity inside of base classes there should be an error. And finally, if field for C++29 is from some base class, find out the corresponding base FIELD_DECL and find out how many consecutive designators belong to the same FIELD_DECL and recurse using reshape_init_r. 2026-08-06 Jakub Jelinek <[email protected]> Jason Merrill <[email protected]> PR c++/125989 gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): Predefine __cpp_designated_initializers to 202606 instead of 201707 for C++29. gcc/cp/ * parser.cc: Implement C++29 P2287R6 - Designated-initializers for Base Classes. (cp_parser_initializer_list): For C++29, allow non-designated clauses followed by designated ones, provided designators are identifiers. For C++20-26, allow that as a pedwarned about extension but use the C++20 wording in that case. * decl.cc (reshape_init_class): Diagnose non-designated clause not appertaining to base class followed by designated clause for C++ >= 20. For C++29, if get_class_binding for designator is unsuccessful, use lookup_member afterwards and handle the case where the lookup succeeds for some member of a base class through recursive reshape_init_class. gcc/testsuite/ * g++.dg/cpp/embed-14.C: Expect different diagnostics for C++29 and sometimes for C++20-C++26 too. * g++.dg/cpp2a/desig2.C: Likewise. * g++.dg/cpp2a/desig13.C: Likewise. * g++.dg/cpp2a/desig20.C: Likewise. * g++.dg/ext/desig4.C: Likewise. * g++.dg/parse/pr43765.C: Likewise. * g++.dg/cpp29/feat-cxx29.C: Expect different value of __cpp_designated_initializers for C++29. * g++.dg/cpp29/desig1.C: New test. * g++.dg/cpp29/desig2.C: New test. * g++.dg/cpp29/desig3.C: New test. * g++.dg/cpp29/desig4.C: New test. * g++.dg/cpp29/desig5.C: New test. * g++.dg/cpp29/desig6.C: New test. * g++.dg/cpp29/desig7.C: New test. * g++.dg/cpp29/desig8.C: New test. * g++.dg/cpp29/desig9.C: New test. * g++.dg/cpp29/desig10.C: New test. * g++.dg/cpp29/desig11.C: New test. * g++.dg/cpp29/desig12.C: New test. * g++.dg/cpp29/desig13.C: New test. * g++.dg/cpp29/desig14.C: New test. * g++.dg/cpp29/desig15.C: New test. * g++.dg/cpp29/desig16.C: New test. Reviewed-by: Jason Merrill <[email protected]>