https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128981
Bug ID: 128981
Summary: Reflecting a dependent name in a template can yield a
buggy non-type reflection value that references a type
Product: gcc
Version: 16.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: marralesfios at gmail dot com
Target Milestone: ---
Created attachment 66278
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66278&action=edit
preprocessed source file
GCC accepts the following self-contradictory code:
#include<meta>
template<typename>
struct templ{
struct type;
};
template<typename T>
constexpr inline std::meta::info buggy = ^^templ<T>::type;
static_assert(!is_type(buggy<int>)); // works but shouldn't
static_assert(requires{typename [:buggy<int>:];}); // also works...?
when compiled with `g++ -std=c++26 -freflection bug.cpp`. Specifically,
`buggy<int>` seems to create a reflection of a type that is not marked as being
a type. Note that changing the definition of `buggy` to `^^typename
templ<T>::type` makes GCC behave as intended.
This seems like unintended behavior. In my understanding of [expr.reflect],
whether the reflected reflection-name `templ<T>::type` should be interpreted as
a type-id, depends on the result of _lookup_, not just whether it
_syntactically_ denotes a type, as determined by [temp.res]. Even if the
Standard is interpreted as disallowing the reflection expression to reflect on
`templ<T>::type` as a type, `buggy<int>` should probably be treated as IF
instead of acting strangely like this.