diff options
author | dmitrykobets-msft <89153909+dmitrykobets-msft@users.noreply.github.com> | 2022-04-14 21:08:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-14 21:08:28 +0300 |
commit | 2bfd4950802a223dde37a08a205812b6dfdfeb61 (patch) | |
tree | 811f620c8256303709cb3a8e130045343ef8a5af /include | |
parent | 383723676cd548d615159701ac3d050f8dd1e128 (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 'include')
-rw-r--r-- | include/gsl/narrow | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/include/gsl/narrow b/include/gsl/narrow index bad581c..2c3c518 100644 --- a/include/gsl/narrow +++ b/include/gsl/narrow @@ -43,10 +43,17 @@ GSL_SUPPRESS(p.2) // NO-FORMAT: attribute // don't rely on undefined behavior // and cannot fit into the destination integral type), the resultant behavior is benign on the platforms
// that we target (i.e., no hardware trap representations are hit).
+#if defined(__clang__) || defined(__GNUC__)
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wfloat-equal"
+#endif
if (static_cast<U>(t) != u || (is_different_signedness && ((t < T{}) != (u < U{}))))
{
throw narrowing_error{};
}
+#if defined(__clang__) || defined(__GNUC__)
+ #pragma GCC diagnostic pop
+#endif
return t;
}
|