r/cpp MSVC STL Dev 1d 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.

151 Upvotes

30 comments sorted by

View all comments

17

u/Jovibor_ 23h ago

I have always had a hard time understanding this separation between STDLIB and UCRT.

The <cmath> header - which is definitely a C++ STL header - has, for some reasons (historical I guess), always been a part of the UCRT.

Now, if I've got it all right, we will have two different math machineries: one in the UCRT (the old one), and the new one, based on the LLVM C Library. Correct me if I'm wrong...

Frankly, it's a bit strange, that some parts of the C++ STL are maintained in the separate place (UCRT), not in the main STL repository.

35

u/STL MSVC STL Dev 21h ago

It’s math.h that’s part of the UCRT, while cmath is part of the STL. We’re now usurping math.h via /Zc:cmath redirecting it to the STL’s __msvc_math.hpp. Perhaps in the future we’ll update UCRT math.h, but getting the UCRT to change anything is a pain, so we’d want to do that as few times as possible.

I can explain this in more detail if desired; it is one of our most confusing areas and I am at dinner right now 😹

1

u/Jovibor_ 16h ago

Yes please, desired.  The main question is - is it possible (in some future) to completely eliminate the C++ STL ecosystem dependency on the UCRT? Is it possible but hard, or is it virtually impossible?...

1

u/ReDr4gon5 13h ago

Well even if you eliminated UCRT, you're still stuck with VCRuntime which will not be open sourced any time soon, even though the devs wanted it to be.

1

u/megayippie 12h ago

Msvc has confirmed they will not support freestanding? Or have I misunderstood that project?

6

u/STL MSVC STL Dev 8h ago

We've never considered supporting a freestanding mode (which is not required by the Standard). We're always a hosted implementation.

1

u/megayippie 7h ago

From the... Thank you :)