From d4e024be11fa942574b7ba51d17aa55e2e368f7e Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 9 Jul 2026 06:56:03 +0200 Subject: [PATCH] Fix MSVC C4702 warning caused by JSON_HEDLEY_NO_RETURN on get_elements() PR #5250 annotated wide_string_input_adapter::get_elements() with JSON_HEDLEY_NO_RETURN (it unconditionally throws). On MSVC this expands to __declspec(noreturn), and MSVC correctly determined that the code following its call in binary_reader.hpp is unreachable for that instantiation, firing C4702 under /W4 /WX in the msvc, msvc-vs2026, and msvc-arm64 Debug jobs. Clang doesn't flag this case, so the Docker verification for #5250 (which only checked Clang -Weverything) didn't catch it. This is the same warning class already tolerated for Release builds since PR #5216, where MSVC's optimizer independently found the same dead code after /Od was removed. Extend that existing /wd4702 suppression to Debug builds too, instead of reverting the noreturn annotation. Signed-off-by: Niels Lohmann --- tests/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 317ada91f..4383b582c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -68,7 +68,11 @@ target_compile_options(test_main PUBLIC # Disable warning C4566: character represented by universal-character-name '\uFF01' # cannot be represented in the current code page (1252) # Disable warning C4996: 'nlohmann::basic_json<...>::operator <<': was declared deprecated - $<$:/W4;/wd4566;/wd4996;$<$:/wd4702>> + # Disable warning C4702: unreachable code; wide_string_input_adapter::get_elements() + # is annotated JSON_HEDLEY_NO_RETURN (it always throws), which + # makes MSVC flag the code following its call in binary_reader.hpp + # as unreachable for that instantiation, in both Debug and Release + $<$:/W4;/wd4566;/wd4996;/wd4702> # https://github.com/nlohmann/json/issues/1114 $<$:/bigobj> $<$:-Wa,-mbig-obj>