[clang] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin and frexp. (PR #88978)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 23 09:04:07 PDT 2024


================
@@ -2922,7 +2922,7 @@ static bool handleFloatFloatBinOp(EvalInfo &Info, const BinaryOperator *E,
   //   If during the evaluation of an expression, the result is not
   //   mathematically defined [...], the behavior is undefined.
   // FIXME: C++ rules require us to not conform to IEEE 754 here.
-  if (LHS.isNaN()) {
+  if (!Info.getLangOpts().CPlusPlus23 && LHS.isNaN()) {
----------------
AaronBallman wrote:

The plot thickens, this may be a case where it's defined in C but C++ doesn't bother defining much of anything about floating-point and thus it is UB: https://github.com/cplusplus/draft/issues/5407

That said, https://eel.is/c++draft/basic.fundamental#12.sentence-8 seems to make this implementation-defined and it would be reasonable for us to define C++ as following the C semantics in situations where C++ is silent on the behavior.

C is more clear on this point. C23 5.2.5.3.3p8: Floating types shall be able to represent signed zeros or an unsigned zero and all normalized floating point numbers. In addition, floating types may be able to contain other kinds of floating-point numbers, such as subnormal floating-point numbers and unnormalized floating-point numbers, and
values that are not floating-point numbers, such as NaNs and (signed and unsigned) infinities.

https://github.com/llvm/llvm-project/pull/88978


More information about the cfe-commits mailing list