diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 14cad1889..8879f2e5e 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -438,11 +438,13 @@ struct string_caster { cast(const StringType &src, return_value_policy /* policy */, handle /* parent */) { const char *buffer = reinterpret_cast(src.data()); auto nbytes = ssize_t(src.size() * sizeof(CharT)); - if (std::is_same::value #if defined(PYBIND11_CPP17) - || std::is_same::value + if constexpr (std::is_same::value || + std::is_same::value) +#else + if (std::is_same::value) #endif - ) { + { return PyBytes_FromStringAndSize(buffer, nbytes); } else { handle s = decode_utfN(buffer, nbytes);