Skip to content

Conversation

tkoeppe
Copy link
Contributor

@tkoeppe tkoeppe commented Sep 8, 2025

Description

Constraints the templates accessor::operator= so that they are not selected in overload resolution when the special members should be selected.

Found by an experimental, new clang-tidy check.

While we may not know the exact design decisions now, it seems unlikely that the special members were deliberately meant to not be selected (for otherwise they could have been defined differently to make this clear). Rather, it seems like an oversight that the operator templates win in overload resolution, and we should restore the intended resolution.

Should not have any observable behaviour.

tkoeppe and others added 4 commits September 8, 2025 15:04
…t match calls that should use the special member functions.

Found by an experimental, new clang-tidy check. While we may not know the exact design decisions now, it seems unlikely that the special members were deliberately meant to not be selected (for otherwise they could have been defined differently to make this clear). Rather, it seems like an oversight that the operator templates win in overload resolution, and we should restore the intended resolution.
@tkoeppe
Copy link
Contributor Author

tkoeppe commented Sep 8, 2025

(To be squashed on commit.)

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

Thanks @tkoeppe!

This bug is super unobvious! (I'm very surprised that the overload resolution is so unintuitive in this case.)

I'll merge this now since all tests pass. If you can think of a unit test that catches this, it'd be ideal to add it in.

@rwgk rwgk merged commit a6581ee into pybind:master Sep 8, 2025
85 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Sep 8, 2025
@tkoeppe
Copy link
Contributor Author

tkoeppe commented Sep 8, 2025

Thanks, Ralf! Yes, that's why we have this new clang-tidy check, I suppose! It'll hopefully be released before long. I'm also running a global test, I'll let you know if anything weird comes up.

@rwgk
Copy link
Collaborator

rwgk commented Sep 8, 2025

I'm also running a global test

Great to know!

Are all the sanitizer tests still in place? (I don't think we have any sanitizer coverage here anymore.)

@tkoeppe
Copy link
Contributor Author

tkoeppe commented Sep 8, 2025

Yes, the pybind.*san tests are all still in place and have passed.

@tkoeppe
Copy link
Contributor Author

tkoeppe commented Sep 9, 2025

@rwgk: And global testing is all good, too.

@rwgk
Copy link
Collaborator

rwgk commented Sep 9, 2025

And global testing is all good, too.

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs changelog Possibly needs a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants