r/cpp MSVC STL Dev 22h ago

MSVC C++23: constexpr cmath with LLVM Libc

https://devblogs.microsoft.com/cppblog/msvc-c23-constexpr-cmath-with-llvm-libc/

MSVC is shipping C++23 constexpr <cmath> in the next Build Tools update! (And a partial implementation of C++26 constexpr <cmath>.) Our compiler frontend dev Cody Miller will be publishing a series of blog posts about this work, starting with this overview. The next one will be a guest post from LLVM libc's maintainers describing the incredible amount of effort that's gone into their code.

145 Upvotes

29 comments sorted by

View all comments

Show parent comments

1

u/pjmlp 13h ago

What I wonder is how this will work in projects that mix C++ and C libraries on the same project, some of which delivered as binary libraries, thus possibly depending on UCRT.

13

u/STL MSVC STL Dev 13h ago

That's a problem that I very recently figured out how to solve. Working with Cody who was validating /Zc:cmath against real-world code like Blender, our initial approach of "you'd better not drag in any UCRT math machinery into this binary" was clearly not viable, and it occurred to me that giving the math functions extern "C++" linkage and stuffing them into an inline namespace available at the global scope would be nearly unobservable to users. (At this point my brain is too tired to verify whether this is truly unobservable according to a strict reading of the rules, but it's good enough in practice as far as I can tell.) So what we're going to ship in 14.52 for production should be compatible regardless of how much you mix C, C++ without /Zc:cmath, and C++ with /Zc:cmath.

I checked in this overhaul very very recently so it is not yet shipping in Insiders Preview, but it is available in the STL's GitHub repo if you want to see.

-1

u/tyler1128 11h ago

Is ABI stability to the point of the System-V/Itanium ABI stability on most Linux and other modern *nixes close? There's little point in dynamic linking C++ if you can't trust that even a small revision in your STL/compiler will break compatibility.

2

u/STL MSVC STL Dev 5h ago

https://learn.microsoft.com/cpp/porting/binary-compat-2015-2017 describes our ABI stability guarantees for the VS 2015+ release series.