Skip to content

Fix #612: "Recommended" way of binding specific function overloads doesn't work on clang 14#701

Merged
lefticus merged 1 commit into
ChaiScript:developfrom
leftibot:fix/issue-612-recommended-way-of-binding-specific-func
May 2, 2026
Merged

Fix #612: "Recommended" way of binding specific function overloads doesn't work on clang 14#701
lefticus merged 1 commit into
ChaiScript:developfrom
leftibot:fix/issue-612-recommended-way-of-binding-specific-func

Conversation

@leftibot

@leftibot leftibot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Automated fix by @leftibot.

What changed

Fix #612: Allow fun(&overloaded) for overload disambiguation
The cheatsheet's "preferred" syntax for binding overloaded free functions,
fun<Ret(Args...)>(&overloaded), only worked on MSVC because the existing
fun(T&&) overload sets T to a function type when called explicitly,
which produces a function rvalue-reference parameter that does not match
a function pointer argument. Standards-conforming compilers (clang, GCC
in some modes) correctly rejected it.
Added two new fun overloads, parameterized on the explicitly-supplied
function-type Signature and using std::type_identity_t to keep that
parameter non-deducible, so they only participate in overload resolution
when Signature is given explicitly. One accepts a free function pointer,
the other a pointer-to-member, enabling both fun<Ret(Args...)>(&free_fn)
and fun<Ret(Args...) cv>(&Class::method) to disambiguate overloads
without resorting to static_cast.

Files

 .../chaiscript/dispatchkit/register_function.hpp   | 37 ++++++++++++
 unittests/compiled_tests.cpp                       | 68 ++++++++++++++++++++++
 2 files changed, 105 insertions(+)

Closes #612

Triggered by @lefticus.

…sambiguation

The cheatsheet's "preferred" syntax for binding overloaded free functions,
fun<Ret(Args...)>(&overloaded), only worked on MSVC because the existing
fun<T>(T&&) overload sets T to a function type when called explicitly,
which produces a function rvalue-reference parameter that does not match
a function pointer argument. Standards-conforming compilers (clang, GCC
in some modes) correctly rejected it.

Added two new fun overloads, parameterized on the explicitly-supplied
function-type Signature and using std::type_identity_t to keep that
parameter non-deducible, so they only participate in overload resolution
when Signature is given explicitly. One accepts a free function pointer,
the other a pointer-to-member, enabling both fun<Ret(Args...)>(&free_fn)
and fun<Ret(Args...) cv>(&Class::method) to disambiguate overloads
without resorting to static_cast.
@lefticus lefticus merged commit d60f8fe into ChaiScript:develop May 2, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Recommended" way of binding specific function overloads doesn't work on clang 14

2 participants