-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix build failure when shared_ptr<T>
points to private
std::enable_shared_from_this
base
#5590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
[Browse private_esft/manuscript tree](https://github.com/rwgk/pybind11/tree/3f2b1201b830d9e431448bd8f5fe577afaa02dbf) [Browse private_esft/manuscript commits](https://github.com/rwgk/pybind11/commits/3f2b1201b830d9e431448bd8f5fe577afaa02dbf/)
Compilation error for the test added with this PR, but without the fix in this PR:
|
shared_ptr<T>
points to private std::enable_shared_from_this
baseshared_ptr<T>
points to private
std::enable_shared_from_this
base
rwgk
added a commit
to rwgk/pybind11
that referenced
this pull request
Mar 30, 2025
henryiii
approved these changes
Mar 30, 2025
Co-authored-by: Henry Schreiner <[email protected]>
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.
Description
pybind11 v3 added
std::enable_shared_from_this
detection logic forshared_ptr<T>
. WhenT
privately inherits fromstd::enable_shared_from_this<T>
, this causes a C++ compilation failure, even ifT
is unbound and never passed from Python.This patch uses a SFINAE-based
type_has_shared_from_this()
overload to gracefully detect this case and preserve the behavior of the v2 release series.The new test in test_shared_ptr.cpp,py
The work on this PR was done with massive assistance from ChatGPT. Unfortunately I (rwgk) cannot share the link to the original conversation, but here is a PDF with most of it.
Initially I "just" wanted a reproducer, to explain a "known issue" in the pybind11 v3 Upgrade guide. This was tricky, because the code generating the original error was not accessible. It took about five iterations of trial-and-error before we (ChatGPT and I) had a reproducer (this took about 90 minutes). Then it took only two iterations (about 15 minutes) until we had the fix that is now in this PR.
A Changelog entry is not needed: This is a compatibility fix for an unreleased feature.
The Upgrade guide does no longer need to mention this!
Browse private_esft/manuscript tree
Browse private_esft/manuscript commits