c++, libstdc++: Implement C++26 P3861R1 - Pragmatic approach to standard structural types
Implements C++26's structural type enhancements using a new attribute and updates libstdc++ for standard library types.
This commit introduces support for the C++26 P3861R1 proposal, which aims for a more pragmatic approach to standard structural types. A new GCC attribute, gnu::structural_type, is added to override the requirement that all base classes and members of a structural type must be public. This attribute is then applied in libstdc++ to class templates like string_view, span, and variant that are intended to behave as structural types in C++26, ensuring their compatibility with the evolving standard.
In Details
This patch implements C++26 P3861R1, which allows the gnu::structural_type attribute to relax the structural type requirement that bases and members must be public. Previously, only public members/bases contributed to structural equivalence. Now, classes with this attribute can have private or protected members/bases, and they will still be considered structurally equivalent if their public interfaces match. Libstdc++ uses this attribute on basic_string_view, span, and variant to align with the upcoming C++26 standard behavior.
- structural type
- In C++, a type whose equivalence is determined by its structure (members and bases) rather than by its name. C++26 is evolving the definition to be more pragmatic.
- libstdc++
- The standard C++ library implementation used by GCC.
- class template
- A blueprint for creating classes that can take template parameters, allowing for generic programming.
- attribute
- A GCC extension that allows programmers to annotate code with additional information for the compiler, affecting compilation behavior or diagnostics.
- C++26
- The upcoming standard version of the C++ programming language, expected to be finalized around 2026.
- P3861R1
- A C++ standardization proposal (P-document) related to structural types.