[Bug c++/126546] New: [c++26] [reflection] reflect-expression rejects pack-index-specifier operand (^^Ts...[0])

121539739 at qq dot com via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126546

            Bug ID: 126546
           Summary: [c++26] [reflection] reflect-expression rejects
                    pack-index-specifier operand (^^Ts...[0])
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 121539739 at qq dot com
  Target Milestone: ---

With -std=c++26 -freflection, applying the reflection operator to a
pack-index-specifier in type position is rejected:

```cpp
#include <meta>

template <class... Ts>
consteval auto first() { return ^^Ts...[0]; }

static_assert(first<int, double>() == ^^int);
```

Command line:

    g++ -std=c++26 -freflection -c repro.cpp

Actual output:

    repro.cpp:4:35: error: '^^' cannot be applied to a pack index
[-Wtemplate-body]
        4 | consteval auto first() { return ^^Ts...[0]; }
          |                                   ^~

Expected: accepted, with ^^Ts...[0] representing the type denoted by
the pack-index-specifier (here, int).

Ts...[0] in type position is a pack-index-specifier
([dcl.type.pack.index]), so "Ts...[0]" forms a valid type-id.
[expr.reflect]/6 places exactly two restrictions on the
"^^ type-id" form: placeholder types are ill-formed (6.1) and
alias templates get special treatment (6.2); otherwise, per (6.3),
"R represents the type denoted by the type-id". Nothing excludes a
pack-index-specifier.

Note that [expr.reflect]/7.4 (Note 3) does make
*pack-index-expressions* ill-formed — but that applies to the
"^^ id-expression" form only. The operand here is a type-id, not
an id-expression, and the error is emitted for the type case.


For reference, Clang's P2996 implementation ("x86-64 clang
(reflection - C++26)" on Compiler Explorer) accept the testcase,
including the static_assert that the result equals ^^int.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.