diff --git a/.github/workflows/static-analyzers.yml b/.github/workflows/static-analyzers.yml index 11c81698..8d768b51 100644 --- a/.github/workflows/static-analyzers.yml +++ b/.github/workflows/static-analyzers.yml @@ -45,7 +45,7 @@ jobs: cmake -S . -B build -DCMAKE_CXX_STANDARD=23 -DUNITS_ENABLE_ERROR_ON_WARNINGS=ON - -DCMAKE_CXX_FLAGS="-Wstrict-overflow=5 -Werror=strict-overflow" + -DCMAKE_CXX_FLAGS="-Wstrict-overflow=2 -Werror=strict-overflow" - name: Build run: cmake --build build --parallel 4 diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2aac17b1..24601fdb 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -110,7 +110,7 @@ jobs: gcc9: containerImage: gcc:9 units.std: 17 - units.options: -DCMAKE_CXX_FLAGS="-Wstrict-overflow=5" + units.options: -DCMAKE_CXX_FLAGS="-Wstrict-overflow=2" gcc11-project_rename: containerImage: gcc:11 units.std: 17 diff --git a/units/units.cpp b/units/units.cpp index c378a3e5..980d1438 100644 --- a/units/units.cpp +++ b/units/units.cpp @@ -2998,6 +2998,10 @@ static char getMatchCharacter(char mchar) // called so coverage isn't expected or required. // do a segment check in the reverse direction +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-overflow" +#endif static bool segmentcheckReverse(const std::string& unit, char closeSegment, int& index) { @@ -3007,12 +3011,10 @@ static bool // LCOV_EXCL_STOP } while (index >= 0) { - const char current = unit[static_cast(index)]; - // Keep the 0 -> -1 transition explicit to avoid -Wstrict-overflow - // on compilers that rewrite signed decrement-and-compare patterns. - index = (index == 0) ? -1 : index - 1; - if (index >= 0 && unit[static_cast(index)] == '\\') { - index = (index == 0) ? -1 : index - 1; + const char current = unit[index]; + --index; + if (index >= 0 && unit[index] == '\\') { + --index; continue; } if (current == closeSegment) { @@ -3041,6 +3043,9 @@ static bool return false; // LCOV_EXCL_STOP } +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif // do a segment check in the forward direction static bool