diff --git a/gcm.cache/nlohmann.json.gcm b/gcm.cache/nlohmann.json.gcm new file mode 100644 index 000000000..b5ca610d3 Binary files /dev/null and b/gcm.cache/nlohmann.json.gcm differ diff --git a/include/nlohmann/detail/view/scan.hpp b/include/nlohmann/detail/view/scan.hpp index 427a53a10..ec684f9b5 100644 --- a/include/nlohmann/detail/view/scan.hpp +++ b/include/nlohmann/detail/view/scan.hpp @@ -85,7 +85,9 @@ NLOHMANN_VIEW_ALWAYS_INLINE const unsigned char* scan_string_run(const unsigned #define NLOHMANN_VIEW_STEP(i) if (NLOHMANN_VIEW_LIKELY(plain[p[i]] != 0)) {} else { p += (i); goto stop; } NLOHMANN_VIEW_STEP(0) NLOHMANN_VIEW_STEP(1) NLOHMANN_VIEW_STEP(2) NLOHMANN_VIEW_STEP(3) NLOHMANN_VIEW_STEP(4) NLOHMANN_VIEW_STEP(5) NLOHMANN_VIEW_STEP(6) NLOHMANN_VIEW_STEP(7) - if (!Value || !NLOHMANN_VIEW_VECTOR) +#if NLOHMANN_VIEW_VECTOR + if (!Value) // (a plain `!Value || !NLOHMANN_VIEW_VECTOR` is a constant condition for MSVC, C4127) +#endif { NLOHMANN_VIEW_STEP(8) NLOHMANN_VIEW_STEP(9) NLOHMANN_VIEW_STEP(10) NLOHMANN_VIEW_STEP(11) NLOHMANN_VIEW_STEP(12) NLOHMANN_VIEW_STEP(13) NLOHMANN_VIEW_STEP(14) NLOHMANN_VIEW_STEP(15) diff --git a/include/nlohmann/detail/view/simd.hpp b/include/nlohmann/detail/view/simd.hpp index f92b62466..4c99c7072 100644 --- a/include/nlohmann/detail/view/simd.hpp +++ b/include/nlohmann/detail/view/simd.hpp @@ -26,6 +26,9 @@ // used where the CPU has SSSE3 (all x86-64 CPUs since about 2011), else the // portable check. JSON_VIEW_USE_SSSE3 skips the CPU check (for code compiled // for SSSE3 anyway); JSON_VIEW_NO_SIMD selects the portable code. +// NLOHMANN_VIEW_NO_TARGET_ATTRIBUTE (set by the GCC module interface, where GCC +// ignores the target attribute and then rejects the SSSE3 intrinsics) keeps the +// check portable without disabling the SSE2 code. #if !defined(JSON_VIEW_NO_SIMD) && defined(__aarch64__) && (defined(__GNUC__) || defined(__clang__)) && NLOHMANN_VIEW_LITTLE_ENDIAN #include #define NLOHMANN_VIEW_NEON 1 @@ -44,7 +47,7 @@ #else #define NLOHMANN_VIEW_SSSE3 0 // NOLINT(cppcoreguidelines-macro-to-enum,modernize-macro-to-enum) #endif -#if NLOHMANN_VIEW_SSE2 && !NLOHMANN_VIEW_SSSE3 && ((defined(__clang__) && __clang_major__ >= 4) || (defined(__GNUC__) && !defined(__clang__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)))) +#if NLOHMANN_VIEW_SSE2 && !NLOHMANN_VIEW_SSSE3 && !defined(NLOHMANN_VIEW_NO_TARGET_ATTRIBUTE) && ((defined(__clang__) && __clang_major__ >= 4) || (defined(__GNUC__) && !defined(__clang__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)))) // (GCC before 4.9 has no SSSE3 intrinsics without -mssse3) #include #include diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index 5e69bd9bd..62f055b94 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -439,6 +439,9 @@ NLOHMANN_JSON_NAMESPACE_END // used where the CPU has SSSE3 (all x86-64 CPUs since about 2011), else the // portable check. JSON_VIEW_USE_SSSE3 skips the CPU check (for code compiled // for SSSE3 anyway); JSON_VIEW_NO_SIMD selects the portable code. +// NLOHMANN_VIEW_NO_TARGET_ATTRIBUTE (set by the GCC module interface, where GCC +// ignores the target attribute and then rejects the SSSE3 intrinsics) keeps the +// check portable without disabling the SSE2 code. #if !defined(JSON_VIEW_NO_SIMD) && defined(__aarch64__) && (defined(__GNUC__) || defined(__clang__)) && NLOHMANN_VIEW_LITTLE_ENDIAN #include #define NLOHMANN_VIEW_NEON 1 @@ -457,7 +460,7 @@ NLOHMANN_JSON_NAMESPACE_END #else #define NLOHMANN_VIEW_SSSE3 0 // NOLINT(cppcoreguidelines-macro-to-enum,modernize-macro-to-enum) #endif -#if NLOHMANN_VIEW_SSE2 && !NLOHMANN_VIEW_SSSE3 && ((defined(__clang__) && __clang_major__ >= 4) || (defined(__GNUC__) && !defined(__clang__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)))) +#if NLOHMANN_VIEW_SSE2 && !NLOHMANN_VIEW_SSSE3 && !defined(NLOHMANN_VIEW_NO_TARGET_ATTRIBUTE) && ((defined(__clang__) && __clang_major__ >= 4) || (defined(__GNUC__) && !defined(__clang__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)))) // (GCC before 4.9 has no SSSE3 intrinsics without -mssse3) #include #include @@ -815,7 +818,9 @@ NLOHMANN_VIEW_ALWAYS_INLINE const unsigned char* scan_string_run(const unsigned #define NLOHMANN_VIEW_STEP(i) if (NLOHMANN_VIEW_LIKELY(plain[p[i]] != 0)) {} else { p += (i); goto stop; } NLOHMANN_VIEW_STEP(0) NLOHMANN_VIEW_STEP(1) NLOHMANN_VIEW_STEP(2) NLOHMANN_VIEW_STEP(3) NLOHMANN_VIEW_STEP(4) NLOHMANN_VIEW_STEP(5) NLOHMANN_VIEW_STEP(6) NLOHMANN_VIEW_STEP(7) - if (!Value || !NLOHMANN_VIEW_VECTOR) +#if NLOHMANN_VIEW_VECTOR + if (!Value) // (a plain `!Value || !NLOHMANN_VIEW_VECTOR` is a constant condition for MSVC, C4127) +#endif { NLOHMANN_VIEW_STEP(8) NLOHMANN_VIEW_STEP(9) NLOHMANN_VIEW_STEP(10) NLOHMANN_VIEW_STEP(11) NLOHMANN_VIEW_STEP(12) NLOHMANN_VIEW_STEP(13) NLOHMANN_VIEW_STEP(14) NLOHMANN_VIEW_STEP(15) diff --git a/src/modules/json.cppm b/src/modules/json.cppm index 940c44ab0..ffc9e00e2 100644 --- a/src/modules/json.cppm +++ b/src/modules/json.cppm @@ -17,6 +17,12 @@ module; // 3. Or upgrade to a newer GCC version with better modules support. // See: https://github.com/nlohmann/json/issues/5103 +// GCC ignores the target attribute in modules ("'target' attribute currently +// unsupported in modules") and then rejects the SSSE3 intrinsics of json_view. +#if defined(__GNUC__) && !defined(__clang__) + #define NLOHMANN_VIEW_NO_TARGET_ATTRIBUTE +#endif + #include #include #include