-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warnings C4715 and C4127 when building json-3.9.1 with Visual Studio 2019 16.7.7 #2592
Comments
Warning
seems to be a false positive, because function Warning
seems to be a false positive. sizeof(typename json::size_type) < sizeof(unsigned long long) is true very often, but not necessarily all the time. |
I'm not sure how to fix any of the warnings. |
sizeof(typename json::size_type) < sizeof(unsigned long long) can be solved in c++17 with if constexpr (sizeof(typename json::size_type) < sizeof(unsigned long long)) |
The default: // LCOV_EXCL_LINE case does not return anything. |
MSVC does not warn about the general case but about the case for the architecture being compiled. |
The library targets C++11. |
That's true, but it also does not leave the function due to the assertion. |
If there were a This may help https://stackoverflow.com/questions/60802864/emulating-gccs-builtin-unreachable-in-visual-studio |
This exact case is covered here: https://docs.microsoft.com/en-us/cpp/intrinsics/assume?view=msvc-160&viewFallbackFrom=vs-2019 |
@gregmarr Thanks for the reference! A default: // LCOV_EXCL_LINE
JSON_ASSERT(false); // LCOV_EXCL_LINE
return 0; // LCOV_EXCL_LINE |
If we already have places where we return after an assert and we're not getting errors there, then adding a return in this case seems like a reasonable fix. |
The issue with the missing return value is fixed in the I went through the code and did not find a similar issue. I would close this issue unless anyone has an idea what to do with C4127. |
Globally disabling? |
I'm not a big fan of that - especially since it seems not to be enabled by default or is it? |
Since the example shown is in a test file, I think it would be acceptable to have a pragma in that file to disable the warning. If it were in the main source, that would be a different story. |
diff --git a/test/src/unit-json_pointer.cpp b/test/src/unit-json_pointer.cpp
index 14d8cd183..fc10c6ff5 100644
--- a/test/src/unit-json_pointer.cpp
+++ b/test/src/unit-json_pointer.cpp
@@ -358,6 +358,10 @@ TEST_CASE("JSON pointers")
CHECK_THROWS_WITH(j_const[jp] == 1, throw_msg.c_str());
}
+#if defined(_MSC_VER)
+#pragma warning (push)
+#pragma warning (disable : 4127) // on some machines, the check below is not constant
+#endif
if (sizeof(typename json::size_type) < sizeof(unsigned long long))
{
auto size_type_max_uul = static_cast<unsigned long long>((std::numeric_limits<json::size_type>::max)());
@@ -371,6 +375,10 @@ TEST_CASE("JSON pointers")
CHECK_THROWS_WITH(j_const[jp] == 1, throw_msg.c_str());
}
+#if defined(_MSC_VER)
+#pragma warning (pop)
+#endif
+
CHECK_THROWS_AS(j.at("/one"_json_pointer) = 1, json::parse_error&);
CHECK_THROWS_WITH(j.at("/one"_json_pointer) = 1,
"[json.exception.parse_error.109] parse error: array index 'one' is not a number"); @gregmarr @t-b @Andreas-Schniertshauer Is this what you'd have in mind? |
I get the following warnings when building json-3.9.1 with Visual Studio 2019 16.7.7:
Please describe the steps to reproduce the issue.
What is the expected behavior?
No warnings
And what is the actual behavior instead?
Warnings
Which compiler and operating system are you using?
Which version of the library did you use?
The text was updated successfully, but these errors were encountered: