pytypes.h: constrain accessor::operator= templates so that they do not obscure special members (#5832)

* pytypes.h: constrain accessor::operator= templates so that they do not 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.

* Use C++11-compatible facilities

* Use C++11-compatible facilities

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Thomas Köppe
2025-09-08 19:52:41 +01:00
committed by GitHub
parent 7fb54e3065
commit a6581eee89

View File

@@ -1039,11 +1039,11 @@ public:
void operator=(const accessor &a) & { operator=(handle(a)); }
template <typename T>
void operator=(T &&value) && {
enable_if_t<!std::is_same<accessor, remove_reference_t<T>>::value> operator=(T &&value) && {
Policy::set(obj, key, object_or_cast(std::forward<T>(value)));
}
template <typename T>
void operator=(T &&value) & {
enable_if_t<!std::is_same<accessor, remove_reference_t<T>>::value> operator=(T &&value) & {
get_cache() = ensure_object(object_or_cast(std::forward<T>(value)));
}