Skip to content

Commit add6628

Browse files
committed
CI-testing a fix for the "ambiguous conversion" issue.
This change is known to fix the `tensorflow::tstring` issue reported under #3521 (comment) TODO: Minimal reproducer for the `tensorflow::tstring` issue.
1 parent f56dc86 commit add6628

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

include/pybind11/pytypes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,8 +1185,10 @@ class bytes : public object {
11851185
}
11861186

11871187
#ifdef PYBIND11_HAS_STRING_VIEW
1188+
// enable_if is needed to avoid "ambiguous conversion" errors (see PR #3521).
11881189
// NOLINTNEXTLINE(google-explicit-constructor)
1189-
bytes(std::string_view s) : bytes(s.data(), s.size()) { }
1190+
template <typename T, detail::enable_if_t<std::is_same<T, std::string_view>::value, int> = 0>
1191+
bytes(T s) : bytes(s.data(), s.size()) { }
11901192

11911193
// Obtain a string view that views the current `bytes` buffer value. Note that this is only
11921194
// valid so long as the `bytes` instance remains alive and so generally should not outlive the

0 commit comments

Comments
 (0)