Skip to content
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

Address regression introduced in #5381 #5396

Merged
merged 21 commits into from
Oct 12, 2024
Merged
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8cf1cdb
Incomplete attempt to address regression introduced in #5381
francesco-ballarin Oct 5, 2024
9d107d2
style: pre-commit fixes
pre-commit-ci[bot] Oct 5, 2024
b508a07
Revert "style: pre-commit fixes"
francesco-ballarin Oct 6, 2024
95e0325
Revert "Incomplete attempt to address regression introduced in #5381"
francesco-ballarin Oct 6, 2024
8cbca65
Simpler fix for the regression introduced in #5381
francesco-ballarin Oct 6, 2024
4c87a23
style: pre-commit fixes
pre-commit-ci[bot] Oct 6, 2024
b375ad7
Added if constexpr workaround
gentlegiantJGC Oct 10, 2024
56758c7
style: pre-commit fixes
pre-commit-ci[bot] Oct 10, 2024
e55e864
Replace if constexpr with template struct
gentlegiantJGC Oct 10, 2024
badb28d
style: pre-commit fixes
pre-commit-ci[bot] Oct 10, 2024
6494448
Made comment clearer
gentlegiantJGC Oct 10, 2024
84cd376
Added test cases
gentlegiantJGC Oct 12, 2024
1c845cf
style: pre-commit fixes
pre-commit-ci[bot] Oct 12, 2024
5965a65
Fixed is_same_or_base_of reference
gentlegiantJGC Oct 12, 2024
add8277
style: pre-commit fixes
pre-commit-ci[bot] Oct 12, 2024
c4ce357
Added static assert messages
gentlegiantJGC Oct 12, 2024
8b9e5d1
style: pre-commit fixes
pre-commit-ci[bot] Oct 12, 2024
ccb165b
Replaced typedef with using
gentlegiantJGC Oct 12, 2024
8bc767d
style: pre-commit fixes
pre-commit-ci[bot] Oct 12, 2024
b7c4fe9
Back out `ForwardClassPtr` (to be discussed separately). Tested local…
rwgk Oct 12, 2024
b778cc6
Shuffle new `static_assert()` and leave error messages blank (they ar…
rwgk Oct 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1564,15 +1564,24 @@ struct function_call {
handle init_self;
};

// See PR #5396 for the discussion that led to this
template <typename Base, typename Derived, typename = void>
struct is_same_or_base_of : std::is_same<Base, Derived> {};

// Only evaluate is_base_of if Derived is complete.
// It will raise a compiler error if Derived is not complete.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC: Neat! (I wish I had known the decltype(void(sizeof(Derived))) trick before!)

However, I find this comment confusing, or I don't actually understand correctly.

Did you mean this?

// This specialization prevents a compiler error if Derived is not complete.

Also, where did you find the decltype(void(sizeof(Derived))) trick?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was based on code from the top of here (linked in my earlier message)
https://devblogs.microsoft.com/oldnewthing/20190710-00/?p=102678

I don't know how official that is though.

I will make the comment more clear.

template <typename Base, typename Derived>
struct is_same_or_base_of<Base, Derived, decltype(void(sizeof(Derived)))>
: any_of<std::is_same<Base, Derived>, std::is_base_of<Base, Derived>> {};

/// Helper class which loads arguments for C++ functions called from Python
template <typename... Args>
class argument_loader {
using indices = make_index_sequence<sizeof...(Args)>;

template <typename Arg>
using argument_is_args = std::is_base_of<args, intrinsic_t<Arg>>;
using argument_is_args = is_same_or_base_of<args, intrinsic_t<Arg>>;
template <typename Arg>
using argument_is_kwargs = std::is_base_of<kwargs, intrinsic_t<Arg>>;
using argument_is_kwargs = is_same_or_base_of<kwargs, intrinsic_t<Arg>>;
// Get kwargs argument position, or -1 if not present:
static constexpr auto kwargs_pos = constexpr_last<argument_is_kwargs, Args...>();

Expand Down