Title
`std::meta::current_function` should probably work in a local class
Status
ready
Section
[meta.reflection.scope]
Submitter
S. B. Tam

Created on 2026-05-31.00:00:00 last changed 3 days ago

Messages

Date: 2026-09-11.16:39:09

Proposed resolution:

This wording is relative to N5046.

  1. Modify [meta.reflection.scope] as indicated:

    consteval info current_function();
    

    -6- An invocation of `current_function` that appears at a program point P is value-dependent ([temp.dep.constexpr]) if eval-point(P) is enclosed by a scope corresponding to a templated entity.

    -7- Let S be CURRENT-SCOPE(P), where P is the point at which the invocation of `current_function` lexically appears.

    -8- Returns: S if S represents a function. Otherwise, a reflection representing the nearest enclosing function of the entity represented by S, ignoring any function call operators of closure types introduced by consteval-block-declarations ([dcl.pre]).

    -9- Throws: `meta::exception` unlessif S does not representrepresents a function and an enclosing function is not found.

Date: 2026-09-15.00:00:00

[ 2026-09-11; LWG telecon. Status changed: New → Ready. ]

Date: 2026-09-15.00:00:00

[ 2026-09-11; Tim provides new wording ]

The invented lambdas from consteval-block-declarations need to be ignored.

Date: 2026-08-15.00:00:00

[ 2026-08-27; Reflector poll. ]

Set priority to 2 after reflector poll.

"we should say this in words, similar to `current_namespace`."

This wording is relative to N5046.

  1. Modify [meta.reflection.scope] as indicated:

    consteval info current_function();
    

    -6- An invocation of `current_function` that appears at a program point P is value-dependent ([temp.dep.constexpr]) if eval-point(P) is enclosed by a scope corresponding to a templated entity.

    -7- Let S be CURRENT-SCOPE(P), where P is the point at which the invocation of `current_function` lexically appears.

    -8- Returns: S if S represents a function. Otherwise, a reflection representing the nearest enclosing function of the entity represented by S.

    -9- Throws: `meta::exception` unless S represents a functionan enclosing function is found.

Date: 2026-06-15.00:00:00

[ 2026-06-16; Ville Voutilainen provides improved wording ]

Date: 2026-06-15.00:00:00

[ 2026-06-16, Barry Revzin provides wording ]

This wording is relative to N5046.

  1. Modify [meta.reflection.scope] as indicated:

    consteval info current_function();
    

    -6- An invocation of `current_function` that appears at a program point P is value-dependent ([temp.dep.constexpr]) if eval-point(P) is enclosed by a scope corresponding to a templated entity.

    -7- Let S be CURRENT-SCOPE(P), where P is the point at which the invocation of `current_function` lexically appears.

    -8- Returns: S if S represents a function. Otherwise, parent_of(S).

    -9- Throws: `meta::exception` unless S represents a function.

Date: 2026-05-31.00:00:00

`std::meta::current_function` is specified to throw if CURRENT-SCOPE(P) does not represent a function. It is implied that `current_function` throws if the call is directly contained in a local class, in which case it's actually in a function body, but indirectly.

This might be an oversight, as neither P3795 (which introduced this function) nor https://wg21.link/P3795/github has any discussion concerning local classes.

Example:

#include <meta>

template<auto V> struct A { static constexpr auto value = V; };

consteval std::meta::info test() {
  struct Local { using T = A<std::meta::current_function()>; }; // valid or not?
  return Local::T::value;
}
History
Date User Action Args
2026-09-11 16:39:09adminsetmessages: + msg16609
2026-09-11 16:39:09adminsetstatus: new -> ready
2026-09-11 07:14:16adminsetmessages: + msg16604
2026-09-10 14:03:08adminsetmessages: + msg16587
2026-06-20 12:23:29adminsetmessages: + msg16488
2026-06-16 16:43:12adminsetmessages: + msg16484
2026-06-16 16:43:12adminsetmessages: + msg16483
2026-05-31 00:00:00admincreate