Skip to content

Commit a6581ee

Browse files
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>
1 parent 7fb54e3 commit a6581ee

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/pybind11/pytypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,11 +1039,11 @@ class accessor : public object_api<accessor<Policy>> {
10391039
void operator=(const accessor &a) & { operator=(handle(a)); }
10401040

10411041
template <typename T>
1042-
void operator=(T &&value) && {
1042+
enable_if_t<!std::is_same<accessor, remove_reference_t<T>>::value> operator=(T &&value) && {
10431043
Policy::set(obj, key, object_or_cast(std::forward<T>(value)));
10441044
}
10451045
template <typename T>
1046-
void operator=(T &&value) & {
1046+
enable_if_t<!std::is_same<accessor, remove_reference_t<T>>::value> operator=(T &&value) & {
10471047
get_cache() = ensure_object(object_or_cast(std::forward<T>(value)));
10481048
}
10491049

0 commit comments

Comments
 (0)