r/cpp • • 17d ago

MSVC 14.52, migration code to C++23

Now that MSVC 14.52 is released with Visual Studio 2026 18.12 I have tried to rebuild the project I am working on with /std:c++23. Thx for finally releasing C++23 support.

I have previously used /std:c++23preview and my assumption was that the migration would be effortless. But not so. So this is a heads up.

Most of the issues I have ran into is related to C++23 and how incomplete types are used in headers. So C++23 changed so that std::unique_ptr destructor now is constexpr. This means that I have to add/move destructor to .cpp source file. For reference, see Github issues https://github.com/microsoft/STL/issues/4215 and https://github.com/microsoft/STL/issues/4417

But I also have issues with code like:

// Forward declaration
class Foo;

class A
{
public:
    void Add(const Foo & foo ) { _foos.push_back(foo); }

private:
    std::vector<Foo> _foos;
};

class Foo
{
};

Godbolt with MSVC 14.51 and /std:c++23preview - https://godbolt.org/z/ae5M53fK1 Works also perfectly well in GCC 16.2 -std=c++23 - https://godbolt.org/z/rhEM5MMhG

As of this writing MSVC 14.52 and /std:c++23 is not yet available on Godbolt.

But I get error C2139: 'Foo': an undefined class is not allowed as an argument to compiler intrinsic type trait '__is_nothrow_constructible'

A tad annoying.

42 Upvotes

23 comments sorted by

View all comments

Show parent comment

4

u/STL MSVC STL Dev 17d ago

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2564r3.html has a one-sentence description:

This paper proposes avoiding the consteval coloring problem (or, at least, mitigating its annoyances) by allowing certain existing constexpr functions to implicitly become consteval functions when those functions can already only be invoked during compile time anyway.

It's pretty hard to explain otherwise without reading the full paper.

1

u/JVApen Clever is an insult, not a compliment. - T. Winters 7d ago

Finally read the paper, looks rather logical: if you inject some consteval code in a constexpr function, the function can be used on a consteval context. That's the behavior you would expect as a user.

I do am surprised that something that sounds so simple would have a noticable impact on PCH as you should already have all info available to instantiate the template.

1

u/greencursordev 7d ago

Wasn't the cause unfortunately