@@ -384,7 +384,11 @@ template <typename StringType, bool IsView = false> struct string_caster {
384
384
385
385
const auto *buffer = reinterpret_cast <const CharT *>(PYBIND11_BYTES_AS_STRING (utfNbytes.ptr ()));
386
386
size_t length = (size_t ) PYBIND11_BYTES_SIZE (utfNbytes.ptr ()) / sizeof (CharT);
387
- if (constexpr_bool (UTF_N > 8 )) { buffer++; length--; } // Skip BOM for UTF-16/32
387
+ // Skip BOM for UTF-16/32
388
+ if (PYBIND11_SILENCE_MSVC_C4127 (UTF_N > 8 )) {
389
+ buffer++;
390
+ length--;
391
+ }
388
392
value = StringType (buffer, length);
389
393
390
394
// If we're loading a string_view we need to keep the encoded Python object alive:
@@ -499,7 +503,7 @@ template <typename CharT> struct type_caster<CharT, enable_if_t<is_std_char_type
499
503
// out how long the first encoded character is in bytes to distinguish between these two
500
504
// errors. We also allow want to allow unicode characters U+0080 through U+00FF, as those
501
505
// can fit into a single char value.
502
- if (constexpr_bool (StringCaster::UTF_N == 8 ) && str_len > 1 && str_len <= 4 ) {
506
+ if (PYBIND11_SILENCE_MSVC_C4127 (StringCaster::UTF_N == 8 ) && str_len > 1 && str_len <= 4 ) {
503
507
auto v0 = static_cast <unsigned char >(value[0 ]);
504
508
// low bits only: 0-127
505
509
// 0b110xxxxx - start of 2-byte sequence
@@ -524,7 +528,7 @@ template <typename CharT> struct type_caster<CharT, enable_if_t<is_std_char_type
524
528
// UTF-16 is much easier: we can only have a surrogate pair for values above U+FFFF, thus a
525
529
// surrogate pair with total length 2 instantly indicates a range error (but not a "your
526
530
// string was too long" error).
527
- else if (constexpr_bool (StringCaster::UTF_N == 16 ) && str_len == 2 ) {
531
+ else if (PYBIND11_SILENCE_MSVC_C4127 (StringCaster::UTF_N == 16 ) && str_len == 2 ) {
528
532
one_char = static_cast <CharT>(value[0 ]);
529
533
if (one_char >= 0xD800 && one_char < 0xE000 )
530
534
throw value_error (" Character code point not in range(0x10000)" );
@@ -778,7 +782,7 @@ struct pyobject_caster {
778
782
// For Python 2, without this implicit conversion, Python code would
779
783
// need to be cluttered with six.ensure_text() or similar, only to be
780
784
// un-cluttered later after Python 2 support is dropped.
781
- if (constexpr_bool (std::is_same<T, str>::value) && isinstance<bytes>(src)) {
785
+ if (PYBIND11_SILENCE_MSVC_C4127 (std::is_same<T, str>::value) && isinstance<bytes>(src)) {
782
786
PyObject *str_from_bytes = PyUnicode_FromEncodedObject (src.ptr (), " utf-8" , nullptr );
783
787
if (!str_from_bytes) throw error_already_set ();
784
788
value = reinterpret_steal<type>(str_from_bytes);
0 commit comments