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.
This commit is contained in:
dmitrykobets-msft
2022-04-14 11:08:28 -07:00
committed by GitHub
parent 383723676c
commit 2bfd495080
3 changed files with 13 additions and 0 deletions

View File

@@ -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