C++ Logo

std-discussion

Advanced search

Surprising error about immediate-escalation

From: Keenan Horrigan <friedkeenan_at_[hidden]>
Date: Sun, 14 Jun 2026 08:22:27 +0000
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?)

2. Is there a way for me to avoid this behavior, and still get my runtime-accessible description of the function in templated contexts?

Any clarification on those questions would be very greatly appreciated.

Thanks

Received on 2026-06-14 08:22:34