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

    21 files      21 suites   3d 7h 14m 28s ⏱️
 3 860 tests  3 860 ✅ 0 💤 0 ❌
73 677 runs  73 677 ✅ 0 💤 0 ❌

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