Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Fix Wold-style-cast error (#2125)

* Add Wold-style-cast to cmake flags
* Fix old style cast in catch_stats.hpp
* Fix old style cast in catch_stats.cpp
Commit
0acb371b9200140ed958d60b86cbb95663ee93bd
Author
Roman Proskuryakov ·
Committer
GitHub
Parents
045feff834db

Files · Download .tar.gz

Changes

 CMake/MiscFunctions.cmake                          | 1 +
 src/catch2/benchmark/detail/catch_stats.cpp        | 2 +-
 src/catch2/benchmark/detail/catch_stats.hpp        | 2 +-
 tests/SelfTest/Baselines/compact.sw.approved.txt   | 2 +-
 tests/SelfTest/Baselines/console.sw.approved.txt   | 2 +-
 tests/SelfTest/Baselines/tap.sw.approved.txt       | 2 +-
 tests/SelfTest/Baselines/xml.sw.approved.txt       | 2 +-
 tests/SelfTest/IntrospectiveTests/String.tests.cpp | 2 +-
 tests/SelfTest/IntrospectiveTests/Xml.tests.cpp    | 2 +-
 9 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/CMake/MiscFunctions.cmake b/CMake/MiscFunctions.cmake
index 262fc5d4..1f0ed865 100644
--- a/CMake/MiscFunctions.cmake
+++ b/CMake/MiscFunctions.cmake
@@ -63,6 +63,7 @@ function(add_warnings_to_targets targets)
           "-Wdeprecated-register"
           "-Wsuggest-override"
           "-Wshadow"
+          "-Wold-style-cast"
         )
         foreach(warning ${CHECKED_WARNING_FLAGS})
             add_cxx_flag_if_supported_to_targets(${warning} "${targets}")
diff --git a/src/catch2/benchmark/detail/catch_stats.cpp b/src/catch2/benchmark/detail/catch_stats.cpp
index 6f6c3802..8e14bfd7 100644
--- a/src/catch2/benchmark/detail/catch_stats.cpp
+++ b/src/catch2/benchmark/detail/catch_stats.cpp
@@ -182,7 +182,7 @@ namespace Catch {
                     double k0 = -n * nd;
                     double k1 = sb2 - n * sg2 + nd;
                     double det = k1 * k1 - 4 * sg2 * k0;
-                    return (int)(-2. * k0 / (k1 + std::sqrt(det)));
+                    return static_cast<int>(-2. * k0 / (k1 + std::sqrt(det)));
                 };
 
                 auto var_out = [n, sb2, sg2](double c) {
diff --git a/src/catch2/benchmark/detail/catch_stats.hpp b/src/catch2/benchmark/detail/catch_stats.hpp
index 6fb8fd58..b8044131 100644
--- a/src/catch2/benchmark/detail/catch_stats.hpp
+++ b/src/catch2/benchmark/detail/catch_stats.hpp
@@ -102,7 +102,7 @@ namespace Catch {
 
                 double accel = sum_cubes / (6 * std::pow(sum_squares, 1.5));
                 int n = static_cast<int>(resample.size());
-                double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / (double)n;
+                double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / static_cast<double>(n);
                 // degenerate case with uniform samples
                 if (prob_n == 0) return { point, point, point, confidence_level };
 
diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt
index 1b6fb40c..4042f171 100644
--- a/tests/SelfTest/Baselines/compact.sw.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.approved.txt
@@ -1342,7 +1342,7 @@ String.tests.cpp:<line number>: passed: s.data() == ss.data() for: "hello world!
 String.tests.cpp:<line number>: passed: s.substr(s.size() + 1, 123).empty() for: true
 String.tests.cpp:<line number>: passed: std::strcmp(ss.c_str(), "world!") == 0 for: 0 == 0
 String.tests.cpp:<line number>: passed: s.substr(1'000'000, 1).empty() for: true
-String.tests.cpp:<line number>: passed: (char*)buffer1 != (char*)buffer2 for: "Hello" != "Hello"
+String.tests.cpp:<line number>: passed: reinterpret_cast<char*>(buffer1) != reinterpret_cast<char*>(buffer2) for: "Hello" != "Hello"
 String.tests.cpp:<line number>: passed: left == right for: Hello == Hello
 String.tests.cpp:<line number>: passed: left != left.substr(0, 3) for: Hello != Hel
 String.tests.cpp:<line number>: passed: sr == "a standard string" for: a standard string == "a standard string"
diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt
index 08b69583..1a8d3ef4 100644
--- a/tests/SelfTest/Baselines/console.sw.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.approved.txt
@@ -9968,7 +9968,7 @@ String.tests.cpp:<line number>
 ...............................................................................
 
 String.tests.cpp:<line number>: PASSED:
-  CHECK( (char*)buffer1 != (char*)buffer2 )
+  CHECK( reinterpret_cast<char*>(buffer1) != reinterpret_cast<char*>(buffer2) )
 with expansion:
   "Hello" != "Hello"
 
diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt
index 40fa0125..b699781e 100644
--- a/tests/SelfTest/Baselines/tap.sw.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.approved.txt
@@ -2598,7 +2598,7 @@ ok {test-number} - std::strcmp(ss.c_str(), "world!") == 0 for: 0 == 0
 # StringRef
 ok {test-number} - s.substr(1'000'000, 1).empty() for: true
 # StringRef
-ok {test-number} - (char*)buffer1 != (char*)buffer2 for: "Hello" != "Hello"
+ok {test-number} - reinterpret_cast<char*>(buffer1) != reinterpret_cast<char*>(buffer2) for: "Hello" != "Hello"
 # StringRef
 ok {test-number} - left == right for: Hello == Hello
 # StringRef
diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt
index ecaa869b..e13949a0 100644
--- a/tests/SelfTest/Baselines/xml.sw.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.approved.txt
@@ -12133,7 +12133,7 @@ Message from section two
       <Section name="Comparisons are deep" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
         <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
           <Original>
-            (char*)buffer1 != (char*)buffer2
+            reinterpret_cast&lt;char*>(buffer1) != reinterpret_cast&lt;char*>(buffer2)
           </Original>
           <Expanded>
             "Hello" != "Hello"
diff --git a/tests/SelfTest/IntrospectiveTests/String.tests.cpp b/tests/SelfTest/IntrospectiveTests/String.tests.cpp
index 3832a2bf..dbc8190b 100644
--- a/tests/SelfTest/IntrospectiveTests/String.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/String.tests.cpp
@@ -79,7 +79,7 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
     SECTION( "Comparisons are deep" ) {
         char buffer1[] = "Hello";
         char buffer2[] = "Hello";
-        CHECK((char*)buffer1 != (char*)buffer2);
+        CHECK(reinterpret_cast<char*>(buffer1) != reinterpret_cast<char*>(buffer2));
 
         StringRef left(buffer1), right(buffer2);
         REQUIRE( left == right );
diff --git a/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp b/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp
index 74f42383..2d375a22 100644
--- a/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp
@@ -41,7 +41,7 @@ TEST_CASE( "XmlEncode", "[XML]" ) {
 
 // Thanks to Peter Bindels (dascandy) for some of the tests
 TEST_CASE("XmlEncode: UTF-8", "[XML][UTF-8][approvals]") {
-#define ESC(lit) (char*)(lit)
+#define ESC(lit) reinterpret_cast<const char*>(lit)
     SECTION("Valid utf-8 strings") {
         CHECK(encode(ESC(u8"Here be 👾")) == ESC(u8"Here be 👾"));
         CHECK(encode(ESC(u8"šš")) == ESC(u8"šš"));