Skip to content

[cppyy] Auto-downcast objects returned through smart pointers#22586

Open
guitargeek wants to merge 2 commits into
root-project:masterfrom
guitargeek:issue-16210
Open

[cppyy] Auto-downcast objects returned through smart pointers#22586
guitargeek wants to merge 2 commits into
root-project:masterfrom
guitargeek:issue-16210

Conversation

@guitargeek

Copy link
Copy Markdown
Contributor

Returning an object by raw pointer already triggers an automatic downcast to its actual (most derived) class, but returning it through a smart pointer (std::unique_ptr, std::shared_ptr) did not: the object was bound as the declared underlying type, so derived-class members were not accessible.

This became more and more of a nuisance as smart pointers become more common in C++ interface.

Therefore, this commit implements automatic downcasting also for returned smart pointers.

Closes #16210.

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Test Results

    22 files      22 suites   3d 19h 16m 5s ⏱️
 3 861 tests  3 859 ✅  0 💤 2 ❌
77 191 runs  77 090 ✅ 99 💤 2 ❌

For more details on these failures, see this check.

Results for commit aac5660.

♻️ This comment has been updated with latest results.

Returning an object by raw pointer already triggers an automatic
downcast to its actual (most derived) class, but returning it through a
smart pointer (`std::unique_ptr`, `std::shared_ptr`) did not: the object
was bound as the declared underlying type, so derived-class members were
not accessible.

This became more and more of a nuisance as smart pointers become more
common in C++ interface.

Therefore, this commit implements automatic downcasting also for returned
smart pointers.

Closes root-project#16210.
Now that also objects returned by smart pointer get automatically
downcasted to the actual type, we don't need to dereference returned
smart pointer objects to trigger the automatic downcasting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PyROOT] Automatic downcasting of smart pointers to actual type

1 participant