TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 228 subscribers
Post #24068 21
Filtering "address of function" overload sets by target constraints

Consider this code:

template <typename R, typename C, typename... Args>
struct OwnerOfImpl<R (C::*)(Args...) const> { using type = C; };
template <typename T> using OwnerOf = OwnerOfImpl<T>::type;

template <typename T>
concept Getter = std::is_member_function_pointer_v<T>
&& requires(T t, OwnerOf<T> const o) {
(o.*t)();
};

template <Getter auto Fn>
struct M {};

struct S {
int m() const;
//void m(int);
};

void gn() {
M<&S::m> x;
}

This compiles. However, if I uncomment the setter overload, it doesn't work. This is because resolving the address of an overloaded function matches the types of the functions in the overload set against the target type, which is `auto` and therefore matches everything.

Is there a proposal that would change this? Specifically, overload resolution here proceeds as follows (references are to N5014, working draft August 2025):

1. Resolve the placeholder according to 9.2.9.7.2. In the example, this resolves to int (M::*)() const in the non-overloaded case and errors out in the overloaded case.
2. Build the overload set, then filter out functions that don't fit according to 12.3. We don't even get here in the overloaded case.

I imagine a change where

1. Placeholder resolving may remain ambiguous in the first phase.
2. There is another filter step when looking at the overload set, something like "If the target is an unresolved placeholder, resolve with the type of the function, then see if any constraints on the target are fulfilled. If resolution fails or the constraints are not fulfilled, remove the function from the overload set."

Has something like this been proposed?

I'm aware of P2825, which would partially obviate the need because I can write the body of `gn` as `M<declcall(std::declval<S const&>().m())> x;` - though the awkward declval syntax for possibly-not-default-constructible types sours me on this.

I'm also aware of P3312, which I believe completely obviates the need for this. But I'm still wondering if the other way has been considered.

https://redd.it/1o7zmw4
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
More from @r_cpp
  1. Oct 14, 2026I tested whether a coding agent would use C++23 ranges without being told Blog post: https…
  2. Oct 14, 2026C++ futures part 1: The mental model https://devblogs.microsoft.com/oldnewthing/20261012-0…
  3. Oct 14, 2026C++ futures part 2: The mental model for std::promise, std::packaged_task https://devblogs…
  4. Oct 12, 2026[Release] slick-logger v2.2.0 — Lock-free asynchronous C++20 logging with multi-process sh…
  5. Oct 12, 2026Cheap alternative to reboot parameters (nohz, rcu, isolcpus) for stable benchmarks When no…
  6. Oct 12, 2026This C++ drama is crazy - Adobe votes no https://www.youtube.com/watch?v=DEqx_NMMH9Q https…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →