`<cmath>`: `constexpr` `fpclassify()` rejects signaling NaNs on x86

未关闭
#6,445 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@ayushsshukla 已经在做这个了。

开始于 2026年9月10日。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
cpp
领域
compilers

调研方向

从 meow.cpp 复现程序开始,使用 /std:c++latest 和 /Zc:cmath 运行所示的 x86 cl 命令。检查通过 __msvc_math.hpp:321 报告的 constexpr 求值路径,并确定 signaling_NaN() 导致浮点异常的原因。当 static_assert 在 x86 上能够成功通过且不再出现此常量求值失败时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug compiler

I could probably work around this in the library by using a bit_cast, but it would be better for the compiler to fix this bug.

D:\GitHub\STL\out\x86>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.52.36725 for x86 (PREVIEW)
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

D:\GitHub\STL\out\x86>type meow.cpp
#include <cassert>
#include <cmath>
#include <limits>

#ifndef _M_IX86
static_assert(false, "Use x86 to repro this failure!");
#endif

constexpr bool test() {
    assert(std::fpclassify(std::numeric_limits<double>::signaling_NaN()) == FP_NAN);
    return true;
}

int main() {
    static_assert(test());
}
D:\GitHub\STL\out\x86>cl /EHsc /nologo /W4 /std:c++latest /Zc:cmath meow.cpp
meow.cpp
meow.cpp(15): error C2131: expression did not evaluate to a constant
D:\GitHub\STL\out\x86\out\inc\__msvc_math.hpp(321): note: failure was caused by a library call raising a floating-point exception
meow.cpp(15): note: the call stack of the evaluation (the oldest call first) is
meow.cpp(15): note: while evaluating function 'bool test(void)'
meow.cpp(10): note: while evaluating function 'int _Msvc_math::fpclassify(double) noexcept'
主要语言
C++
星标
11.2k
派生
1.7k
平均合并
4 天 4 小时
30 天内合并 PR
14

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/STL 的其他 Issue

查看 microsoft/STL 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。