Date: Sun, 14 Jun 2026 23:30:10 +0100
On 14/06/2026 09:22, Keenan Horrigan via Std-Discussion wrote:
> Hi,
>
> I'm trying to use std::meta::current_function in a default parameter so that I can pack certain compile-time information about the calling-function into an object that I can then access at runtime.
>
> And what I have seems to work great, but I just ran into a case involving templated functions where the compiler ends up telling me that it escalated a function to consteval, and so I can't actually call it at runtime.
>
> I've reduced the issue to the following code:
>
> #include <meta>
>
> struct blah {
> consteval blah(std::meta::info f = std::meta::current_function()) {
> (void) identifier_of(f);
> }
> };
>
> constexpr void bar(int, blah = {}) {}
>
> constexpr void foo(auto x) {
> bar(x);
> }
>
> int main(int argc, char **) {
> foo(argc);
> }
>
> And here's a godbolt link: https://godbolt.org/z/dPE9PPT6P
>
> Both GCC and Clang (if one translates the call to std::meta::current_function to one involving std::meta::access_context::current) emit an error for this code pertaining to immediate-escalation.
>
> If one were to either make 'foo' not templated, or were to remove the 'identifier_of(f)' call in the 'blah' constructor, then the code would compile successfully.
>
> So I guess I'm wondering:
>
> 1. Why is this happening? It does not feel very intuitive to me. (And a corollary to this question, is this behavior intentional?)
`identifier_of` throws `std::meta::exception` for a function template specialisation, as
`has_identifier` is false for it. It makes the constructor call to `blah` not a constant
expression, so it escalates, hence the confusing error.
> 2. Is there a way for me to avoid this behavior, and still get my runtime-accessible description of the function in templated contexts?
You can look at `has_template_arguments`, `template_of` and `template_arguments_of` and
decide what to do with them.
You can call `identifier_of(template_of(f))` in your example: https://godbolt.org/z/784Wz4Woz
> Any clarification on those questions would be very greatly appreciated.
>
> Thanks
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> Hi,
>
> I'm trying to use std::meta::current_function in a default parameter so that I can pack certain compile-time information about the calling-function into an object that I can then access at runtime.
>
> And what I have seems to work great, but I just ran into a case involving templated functions where the compiler ends up telling me that it escalated a function to consteval, and so I can't actually call it at runtime.
>
> I've reduced the issue to the following code:
>
> #include <meta>
>
> struct blah {
> consteval blah(std::meta::info f = std::meta::current_function()) {
> (void) identifier_of(f);
> }
> };
>
> constexpr void bar(int, blah = {}) {}
>
> constexpr void foo(auto x) {
> bar(x);
> }
>
> int main(int argc, char **) {
> foo(argc);
> }
>
> And here's a godbolt link: https://godbolt.org/z/dPE9PPT6P
>
> Both GCC and Clang (if one translates the call to std::meta::current_function to one involving std::meta::access_context::current) emit an error for this code pertaining to immediate-escalation.
>
> If one were to either make 'foo' not templated, or were to remove the 'identifier_of(f)' call in the 'blah' constructor, then the code would compile successfully.
>
> So I guess I'm wondering:
>
> 1. Why is this happening? It does not feel very intuitive to me. (And a corollary to this question, is this behavior intentional?)
`identifier_of` throws `std::meta::exception` for a function template specialisation, as
`has_identifier` is false for it. It makes the constructor call to `blah` not a constant
expression, so it escalates, hence the confusing error.
> 2. Is there a way for me to avoid this behavior, and still get my runtime-accessible description of the function in templated contexts?
You can look at `has_template_arguments`, `template_of` and `template_arguments_of` and
decide what to do with them.
You can call `identifier_of(template_of(f))` in your example: https://godbolt.org/z/784Wz4Woz
> Any clarification on those questions would be very greatly appreciated.
>
> Thanks
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
Received on 2026-06-14 22:30:18
