-
What is the issue you have?
Compiler warning about this line in version 3.2.0
|
if (JSON_LIKELY(*range <= current and current <= *(++range))) |
That line is (almost) unchanged in the current version
|
if (JSON_HEDLEY_LIKELY(*range <= current and current <= *(++range))) |
-
What is the expected behavior?
No warnings :)
-
And what is the actual behavior instead?
warning: unsequenced modification and access to 'range' [-Wunsequenced]
if (JSON_LIKELY(*range <= current and current <= *(++range)))
^ ~
1 warning generated.
- Which compiler and operating system are you using? Is it a supported compiler?
clang, probably version 3.4.0
CentOS 6 (probably, or possibly 7).
- Did you use a released version of the library or the version from the
develop branch?
Version 3.2.0
- If you experience a compilation error: can you compile and run the unit tests?
Probably not. The warning was reported by our CI system, which runs tests on whichever of many servers is available, and they have different configurations, in particular different compiler & OS versions. I can't tell which specific machine reported this, and I can't reproduce it on my development system (CentOS 7, clang 3.4.2).
The offending line actually looks perfectly OK to me -- and should be a sequence point -- although not for overloaded operator&&, but this instance has a bool on each side (unless there's some bizarre overloading of operator<= going on).
It could be related to clang not quite treating and the same as &&. Or it could be related to the JSON_LIKELY() macro, and misbehaviour of __builtin_expect(x) when x has side-effects.
Anyway, I have fixed this locally by explicitly fetching the range elements in a well-defined sequence (low first, then high) before using them in the comparison (which is then guaranteed to have no side-effects).
@@ class lexer
- for (auto range = ranges.begin(); range != ranges.end(); ++range)
+ for (auto range = ranges.begin(); range != ranges.end(); )
{
+ // Fetch range elements in a well-defined order
+ const int low = *range++;
+ const int high = *range++;
get();
- if (JSON_LIKELY(*range <= current and current <= *(++range)))
+ if (JSON_LIKELY(low <= current and current <= high))
What is the issue you have?
Compiler warning about this line in version 3.2.0
json/include/nlohmann/detail/input/lexer.hpp
Line 197 in 9f3857e
That line is (almost) unchanged in the current version
json/include/nlohmann/detail/input/lexer.hpp
Line 206 in ffe0e3d
What is the expected behavior?
No warnings :)
And what is the actual behavior instead?
clang, probably version 3.4.0
CentOS 6 (probably, or possibly 7).
developbranch?Version 3.2.0
Probably not. The warning was reported by our CI system, which runs tests on whichever of many servers is available, and they have different configurations, in particular different compiler & OS versions. I can't tell which specific machine reported this, and I can't reproduce it on my development system (CentOS 7, clang 3.4.2).
The offending line actually looks perfectly OK to me --
andshould be a sequence point -- although not for overloadedoperator&&, but this instance has a bool on each side (unless there's some bizarre overloading ofoperator<=going on).It could be related to clang not quite treating
andthe same as&&. Or it could be related to theJSON_LIKELY()macro, and misbehaviour of__builtin_expect(x)whenxhas side-effects.Anyway, I have fixed this locally by explicitly fetching the range elements in a well-defined sequence (low first, then high) before using them in the comparison (which is then guaranteed to have no side-effects).