use if constexpr under PYBIND11_CPP17 to fix compilation warning

This commit is contained in:
Guillaume Giraud 2022-04-02 13:14:41 +02:00
parent 19d8f06c52
commit 1334c7eae7
1 changed files with 5 additions and 3 deletions

View File

@ -438,11 +438,13 @@ struct string_caster {
cast(const StringType &src, return_value_policy /* policy */, handle /* parent */) { cast(const StringType &src, return_value_policy /* policy */, handle /* parent */) {
const char *buffer = reinterpret_cast<const char *>(src.data()); const char *buffer = reinterpret_cast<const char *>(src.data());
auto nbytes = ssize_t(src.size() * sizeof(CharT)); auto nbytes = ssize_t(src.size() * sizeof(CharT));
if (std::is_same<CharT, uint8_t>::value
#if defined(PYBIND11_CPP17) #if defined(PYBIND11_CPP17)
|| std::is_same<CharT, std::byte>::value if constexpr (std::is_same<CharT, uint8_t>::value ||
std::is_same<CharT, std::byte>::value)
#else
if (std::is_same<CharT, uint8_t>::value)
#endif #endif
) { {
return PyBytes_FromStringAndSize(buffer, nbytes); return PyBytes_FromStringAndSize(buffer, nbytes);
} else { } else {
handle s = decode_utfN(buffer, nbytes); handle s = decode_utfN(buffer, nbytes);