Repository navigation
Description
🤖 AI-generated (drafted with GitHub Copilot CLI; repros verified with the public 14.52.37025 toolset)
Describe the bug
With /Zc:cmath, #include <math.h> is redirected to <__msvc_math.hpp>, which doesn't declare any abs overload. The abs overloads are only in <__msvc_stdlib.hpp> (stl/inc/__msvc_math.hpp line 297 on main: // abs() is in <__msvc_stdlib.hpp>). A C++ translation unit that includes <math.h> and calls abs gets C3861.
This is non-conforming. Per [support.c.headers.other]/1, <math.h> makes every name that <cmath> declares in namespace std available in the global namespace. Per [cmath.syn]/[c.math.abs], <cmath> declares abs(int), abs(long), abs(long long), abs(float), abs(double) and abs(long double).
It's also a regression from the default mode. There, UCRT's <corecrt_math.h> declares int abs(int) (plus the C functions labs/llabs), so abs(-1) compiles, and abs(-2L) compiles by converting to int. Under /Zc:cmath, <math.h> also stops declaring labs/llabs: that part is a compatibility regression rather than a conformance bug.
It also breaks #pragma intrinsic(abs) after <math.h>: C4164 "intrinsic function not declared".
Command-line test case
C:\Temp>type meow.cpp
#include <math.h>
int main() {
return abs(-1) + abs(-2L) == 3 ? 0 : 1;
}
C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /c meow.cpp
meow.cpp
C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /Zc:cmath /c meow.cpp
meow.cpp
meow.cpp(4): error C3861: 'abs': identifier not found
meow.cpp(4): error C3861: 'abs': identifier not found
The long and floating-point overloads were already missing from <math.h> without /Zc:cmath (abs(-1.5) gives C4578), but abs(int) used to work.
Expected behavior
<math.h> declares all six abs overloads in the global namespace. For example, <__msvc_math.hpp> could include <__msvc_stdlib.hpp>'s abs family, or move the floating-point abs overloads into <__msvc_math.hpp> and pull in the integer ones.
STL version
MSVC Build Tools 14.52.37025 (VS 2026 public, cl 19.52.37029.0); same on main.
Additional context
Searched existing issues for abs/math.h/Zc:cmath/__msvc_math.hpp; the only /Zc:cmath hit is #6445, which is unrelated. In a large codebase this broke abs users that include only <math.h> (for example a header doing #include <math.h> then #pragma intrinsic(abs)).
Activity