Skip to content

Commit 3a395e6

Browse files
committed
Fix ambiguous str(kwargs) overload using SFINAE
1 parent 4bbcdee commit 3a395e6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

include/pybind11/pytypes.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,10 +1640,12 @@ class str : public object {
16401640
str(std::u8string_view s) : str(reinterpret_cast<const char *>(s.data()), s.size()) {}
16411641
# endif
16421642

1643-
// Avoid ambiguity when converting from kwargs (GCC)
1644-
explicit str(const kwargs &k) : str(static_cast<handle>(k)) {}
16451643

16461644
#endif
1645+
// Avoid ambiguity when converting from kwargs (GCC)
1646+
template <typename T,
1647+
detail::enable_if_t<std::is_same<T, kwargs>::value, int> = 0>
1648+
explicit str(const T &k) : str(static_cast<handle>(k)) {}
16471649

16481650
explicit str(const bytes &b);
16491651

0 commit comments

Comments
 (0)