Skip to content

Commit

Permalink
Document potentially confusing behavior in gsl::narrow (microsoft#1073)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmitrykobets-msft authored Dec 24, 2022
1 parent 6c6111a commit 46c7271
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions include/gsl/narrow
Original file line number Diff line number Diff line change
Expand Up @@ -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<U>(t) != u || (is_different_signedness && ((t < T{}) != (u < U{}))))
{
throw narrowing_error{};
Expand Down

0 comments on commit 46c7271

Please sign in to comment.