Allow C++ reflection of pack-index-specifiers
Corrects C++ reflection to allow `^^` with type pack expansion specifiers.
This commit corrects the C++ reflection mechanism to properly handle pack-index-specifiers with the ^^ (reflection) operator. The C++ standard specifies that reflections of pack-index-expressions are ill-formed, but this restriction does not apply to pack-index-specifiers when used with types. The GCC compiler previously incorrectly rejected pack-index-specifiers in this context. This change modifies the get_reflection function to distinguish between pack-index-expressions and pack-index-specifiers, allowing the latter to be reflected and fixing a bug reported in PR126546.
In Details
The C++ reflection implementation in GCC (reflect.cc) interprets reflection expressions. This change addresses PR126546 concerning the ^^ operator and pack expansion. According to the C++ standard ([expr.reflect]), a reflection of a pack-index-expression (e.g., args...[0]) is ill-formed. However, a pack-index-specifier (used for types, e.g., T...[0]) is permitted in certain reflection contexts, specifically with ^^type-id. The previous implementation in get_reflection incorrectly checked for PACK_INDEX_P (which includes specifiers) instead of PACK_INDEX_EXPR. This commit cor…
- reflection
- A feature in some programming languages that allows code to inspect, introspect, and modify its own structure and behavior at runtime or compile time. In C++, this is an evolving area, allowing compile-time examination of types and entities.
- pack-index-specifier
- In C++ template metaprogramming, this refers to a mechanism used to refer to a specific element within a parameter pack when dealing with types. It allows specifying an index for a type within a pack expansion.
- pack-index-expression
- Similar to a pack-index-specifier, but applied to expressions within a parameter pack. It allows specifying an index for an expression within a pack expansion.
- PACK_INDEX_P
- A flag or condition within the GCC C++ front-end that indicates the presence of a pack index, which could be either a specifier or an expression. This commit refines the check to distinguish between the two.
- PACK_INDEX_EXPR
- A flag or condition within the GCC C++ front-end specifically indicating a pack index *expression*, as opposed to a pack index *specifier*.