From 46c72713f2e8a66782ba0d40c4d6bb3edc9aa382 Mon Sep 17 00:00:00 2001 From: dmitrykobets-msft <89153909+dmitrykobets-msft@users.noreply.github.com> Date: Sat, 24 Dec 2022 11:49:26 -0800 Subject: [PATCH] Document potentially confusing behavior in gsl::narrow (#1073) NaN != Nan, so the comparisons used in gsl::narrow will always throw when attempting to cast a NaN value. This may be surprising, so document it. --- include/gsl/narrow | 1 + 1 file changed, 1 insertion(+) diff --git a/include/gsl/narrow b/include/gsl/narrow index 7578c8b..5c87087 100644 --- a/include/gsl/narrow +++ b/include/gsl/narrow @@ -52,6 +52,7 @@ GSL_SUPPRESS(p.2) // NO-FORMAT: attribute // don't rely on undefined behavior #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wfloat-equal" #endif + // Note: NaN will always throw, since NaN != NaN if (static_cast(t) != u || (is_different_signedness && ((t < T{}) != (u < U{})))) { throw narrowing_error{};