diff --git a/include/nlohmann/detail/view/edit_storage.hpp b/include/nlohmann/detail/view/edit_storage.hpp index 11bff9faa..372bb3049 100644 --- a/include/nlohmann/detail/view/edit_storage.hpp +++ b/include/nlohmann/detail/view/edit_storage.hpp @@ -177,7 +177,7 @@ inline node* block_of(document_data& d, node* n, std::size_t extra) /// still covers its original subtree. inline node* find_parent(const document_data& d, const node* target) { - const std::less lt; + const std::less lt{}; const node* lo = d.tape; const node* hi = d.tape + d.tape_size; const node* c = d.tape; diff --git a/include/nlohmann/json_view.hpp b/include/nlohmann/json_view.hpp index 0b65ed96b..03ba3fb64 100644 --- a/include/nlohmann/json_view.hpp +++ b/include/nlohmann/json_view.hpp @@ -702,11 +702,19 @@ class basic_json_view return detail::view::view_side(v); } + /// the template argument as a runtime condition: testing it directly in + /// `Editable && ...` makes the condition constant, which MSVC reports as + /// C4127 + static bool editable() noexcept + { + return Editable; + } + /// the number of source bytes of this value (estimated for values with /// decoded strings) std::size_t source_extent() const noexcept { - if (Editable && m_doc->edits != nullptr) + if (editable() && m_doc->edits != nullptr) { // positions of moved and new values are not source offsets return m_node == m_doc->tape ? m_doc->size + m_doc->edits->text_used : 64; diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index 236186820..1bf28ef24 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -2737,7 +2737,7 @@ inline node* block_of(document_data& d, node* n, std::size_t extra) /// still covers its original subtree. inline node* find_parent(const document_data& d, const node* target) { - const std::less lt; + const std::less lt{}; const node* lo = d.tape; const node* hi = d.tape + d.tape_size; const node* c = d.tape; @@ -6015,11 +6015,19 @@ class basic_json_view return detail::view::view_side(v); } + /// the template argument as a runtime condition: testing it directly in + /// `Editable && ...` makes the condition constant, which MSVC reports as + /// C4127 + static bool editable() noexcept + { + return Editable; + } + /// the number of source bytes of this value (estimated for values with /// decoded strings) std::size_t source_extent() const noexcept { - if (Editable && m_doc->edits != nullptr) + if (editable() && m_doc->edits != nullptr) { // positions of moved and new values are not source offsets return m_node == m_doc->tape ? m_doc->size + m_doc->edits->text_used : 64;