GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++/reflection

Skip templated clones in members_of for reflection

Reflection's `members_of` now correctly ignores templated constructor clones.

GCC’s C++ reflection facility, specifically the members_of function, now correctly handles templated constructor clones. Previously, it would include duplicate entries for templated constructors and their clones, such as __ct, __ct_comp, and __ct_base. This change modifies class_members_of to skip templated clones, ensuring that the reflection API returns a clean list of members.

In Details

In gcc/cp/reflect.cc, the class_members_of function's logic for skipping cloned declarations has been extended to also handle templated clones. The DECL_CLONED_FUNCTION_P check previously missed templated functions, leading to members_of including multiple instances of constructors generated from templates. This commit adds a check to exclude these templated clones, resolving PR127643.

For Context
reflection
A programming technique that allows code to inspect and modify its own structure and behavior at runtime or compile time. In C++, this refers to compile-time reflection features.
members_of
A function or operation within C++ reflection that returns a list of members belonging to a specified class.
template clone
A copy or instantiation of a function or class template, often generated by the compiler.
ctor
Abbreviation for constructor, a special member function that initializes an object of a class.
Filed Under: c++reflectioncompiler