Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/GSL.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordmitrykobets-msft <89153909+dmitrykobets-msft@users.noreply.github.com>2022-04-14 21:08:28 +0300
committerGitHub <noreply@github.com>2022-04-14 21:08:28 +0300
commit2bfd4950802a223dde37a08a205812b6dfdfeb61 (patch)
tree811f620c8256303709cb3a8e130045343ef8a5af /tests
parent383723676cd548d615159701ac3d050f8dd1e128 (diff)
Suppress -Wfloat-equal warning in implementation of gsl::narrow (#1043)
In the implementation of gsl::narrow, there is a comparison `static_cast<U>(t) != u` which may be comparing two floats. The comparison here is done purposefully to categorize ill effects of narrowing conversion, since the values being compared *should* be the same when compared with `operator==`. Note, using #pragma GCC will suppress this warning for both GCC and Clang.
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/utils_tests.cpp2
2 files changed, 6 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 891569b..68e18ec 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -89,6 +89,7 @@ if(MSVC) # MSVC or simulating MSVC
>
$<$<CXX_COMPILER_ID:Clang>:
-Weverything
+ -Wfloat-equal
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-covered-switch-default # GTest
@@ -122,6 +123,7 @@ else()
-Wpedantic
-Wshadow
-Wsign-conversion
+ -Wfloat-equal
-Wno-deprecated-declarations # Allow tests for [[deprecated]] elements
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Weverything
@@ -227,6 +229,7 @@ if(MSVC) # MSVC or simulating MSVC
>
$<$<CXX_COMPILER_ID:Clang>:
-Weverything
+ -Wfloat-equal
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-missing-prototypes
@@ -250,6 +253,7 @@ else()
-Wpedantic
-Wshadow
-Wsign-conversion
+ -Wfloat-equal
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Weverything
-Wno-c++98-compat
diff --git a/tests/utils_tests.cpp b/tests/utils_tests.cpp
index 39b4ca2..715073f 100644
--- a/tests/utils_tests.cpp
+++ b/tests/utils_tests.cpp
@@ -149,5 +149,7 @@ TEST(utils_tests, narrow)
EXPECT_TRUE(
narrow<std::complex<float>>(std::complex<double>(4, 2)) == std::complex<float>(4, 2));
EXPECT_THROW(narrow<std::complex<float>>(std::complex<double>(4.2)), narrowing_error);
+
+ EXPECT_TRUE(narrow<int>(float(1)) == 1);
}
#endif // GSL_KERNEL_MODE