C++ Logo

std-discussion

Advanced search

Re: Proper behavior of block-scope function overload declarations and reflection

From: Keenan Horrigan <friedkeenan_at_[hidden]>
Date: Fri, 03 Apr 2026 15:56:06 +0000
Yep, that does appear to work. Thank you very much for letting me know.

On Friday, April 3rd, 2026 at 4:52 AM, Lénárd Szolnoki <cpp_at_[hidden]> wrote:

>
>
> On 2 April 2026 04:48:53 BST, Keenan Horrigan via Std-Discussion <std-discussion_at_[hidden]> wrote:
> >Hello,
> >
> >Today I was poking around some more with reflection, and I came up with the following code which would appear to "peel off" particular overloads out of a function's overload set, getting a reflection of one overload of that function:
> >
> >void function(int integer) {
> > std::printf("int\n");
> >}
> >
> >void function(char character) {
> > std::printf("char\n");
> >}
> >
> >consteval auto get_function_int() {
> > void function(int);
> >
> > return ^^function;
> >}
> >
> >static_assert(
> > identifier_of(
> > parameters_of(get_function_int())[0]
> > )
> >
> > == "integer"
> >);
> >
> >int main() {
> > [: get_function_int() :]('h');
> >}
> >
> >On both GCC and the experimental Clang reflection branch, this prints "int" and the static assert succeeds: https://godbolt.org/z/5caY3rh8d
> >
> >On Clang you can even have
> >
> >template<typename T>
> >consteval auto get_function() {
> > void function(T);
> >
> > return ^^function;
> >}
> >
> >And then get at the overload generically like 'get_function<int>()'. GCC currently runs into an internal error with that, though: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124756
> >
> >But basically, I was wondering if this is valid behavior or not. It would be potentially useful, since I'm not aware of another way to get a reflection of a particular overload from an overload set. But I'm unsure if I could rely on this behavior.
>
> You can also reflect on the namespace (^^::) and iterate through its members to get each individual overload, AFAIK.
>
> >
> >Thanks
>

Received on 2026-04-03 15:56:16