fix: returning a copyable type with a deleted move constructor - #6143
Merged
henryiii merged 2 commits intoAug 14, 2026
Conversation
…d#6142) detail::function_ref's constructor SFINAE required is_convertible<Ret, Ret>, which is false for a copyable type whose move constructor is explicitly deleted (the trait tests conversion from an xvalue). In C++17, such a prvalue return is legal via guaranteed copy elision, so also accept an exact type match. Regression introduced in 3.1.0 by the call_impl outlining (pybind#5887). Fixes pybind#6142 Assisted-by: ClaudeCode:claude-fable-5
Skylion007
reviewed
Aug 12, 2026
Per review: the feature-test macro expresses the intent more precisely than PYBIND11_CPP17. Assisted-by: ClaudeCode:claude-opus-5
Skylion007
approved these changes
Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
Description
Fixes #6142, a 3.1.0 regression from the
call_imploutlining in #5887.detail::function_ref's constructor SFINAE requiresis_convertible<decltype(f(args...)), Ret>. For a copyable type whose move constructor is explicitly deleted,is_convertible<Ret, Ret>is false, because the trait tests conversion from an xvalue, which selects the deleted move constructor. In C++17 such a prvalue return is legal via guaranteed copy elision, so the constraint rejected code the function body compiles fine. The fix also accepts an exact type match (C++17 and later only; in C++14 such a type cannot be returned by value at all).The regression test fails to compile without the fix and is guarded for C++17, since the C++14 CI builds cannot express the case.
Suggested changelog entry: