https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127427
Bug ID: 127427
Summary: GCC is too quick to reject reflecting types that
involves names introduced by using-declarations
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: gcov-profile
Assignee: unassigned at gcc dot gnu.org
Reporter: programmer00001h at gmail dot com
Target Milestone: ---
Consider the following code:
```
namespace foo{
struct T{};
}
using foo::T;
[[maybe_unused]] constexpr auto u = ^^T*;
```
GCC rejects this code, saying
err.cpp:6:39: error: ‘^^’ cannot be applied to a using-declaration
6 | [[maybe_unused]] constexpr auto u = ^^T*;
| ^
err.cpp:6:41: error: expected primary-expression before ‘;’ token
6 | [[maybe_unused]] constexpr auto u = ^^T*;
| ^
However, by [expr.reflect]#3 (https://eel.is/c++draft/expr.reflect#3)
> A reflect-expression is parsed as the longest possible sequence of tokens
> that could syntactically form a reflect-expression.
In `^^T*;`, the longest possible sequence of tokens form the reflect-expression
`^^T*`, and `T*` is a type-id. The reflect-expression should be valid.
However, GCC seems to erroneously treat the reflect-expression as `^^T`, with
`T` being a reflection-name, and reject the program on the grounds of
[expr.reflect]#5.1.
This is pure speculation from the second error message, but GCC might've bailed
out before even *considering* the fact that the suffix asterisk could be part
of the type name, which is wrong.
Output of gcc -v:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/16/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust,cobol
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-gcc-major-version-only
--with-linker-hash-style=gnu --with-system-zlib --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-fixincludes --disable-libssp
--disable-libstdcxx-pch --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.2.1 20260810 (GCC)