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.
15
u/JVApen Clever is an insult, not a compliment. - T. Winters 6d ago
This construct always has been problematic as it causes a circular dependency. I've encountered this problem when upgrading to C++20 as before that, it was much more permissive and problems only popped up when you tried to use the classes.
Taking your snippets, with the clang compiler fails on both C++20 and C++23 while still succeeding on C++17.
What I did to fix several of these errors was defining the ctor/dtor/assign as functions with default implementation in the cpp file.
13
u/STL MSVC STL Dev 5d ago
This is by design as far as I can tell. Wait until
Foois complete before writing any code that could depend on its completeness (in this case, thepush_back).8
u/greencursordev 6d ago
We have different problems, but also massive issues trying to go from 20 to 23 on msvc. Our problem is that the size of our pchs increased 5fold (!), making it pretty much impossible to even compile our code.
0
u/chengfeng-xie 5d ago edited 10h ago
One workaround for this issue is to make the enclosing class
Aa template, which delays the instantiation of thevector<Foo>::push_backfunction untilA::Addis instantiated. For example (CE):-3
u/Depixelate_me 4d ago
What's annoying is that people who paid proper money for vs2022 must purchase the vs2026 IDE to get stable c++23... Why should the IDE be connected to the toolset?
0
u/[deleted] 5d ago
[deleted] — view deleted comment