ARTICLE AD BOX
What changed in C++20 and later versions that caused the program to be rejected?
Flag /permissive- is enabled by default from C++20 in msvc. Microsoft has many extensions that results in successful compilation of an invalid C++ program. If you use /permissive- flag with C++17, you'll notice that msvc also starts rejecting the said program(which is incorrect behavior as the program is well-formed). This means that msvc was already rejecting the program(as far as standard compliance is concerned)
There is a closely related msvc bug that was fixed just 4 days ago(on 19-feb-2023). The reported bug says:
A fix for this issue is now available in preview release. Try out the fix by installing the most recent preview from https://visualstudio.microsoft.com/vs/preview/.
49.4k7 gold badges46 silver badges100 bronze badges
In C++20, even if a variable is constexpr, if you take its address or pass an array (which decays to a pointer), it is "ODR-used." This requires the variable to be captured.
void f(const void*) {} int main() { constexpr float one[1] = { 1.0f }; // Capture the pointer to the array explicitly [ptr = one]() { f(ptr); f(&ptr[0]); }(); }72.6k4 gold badges42 silver badges95 bronze badges
2 Comments
But OP already does capture the variable by refence. And other compilers compile his code just fine godbolt.org/z/5G98nWP9f
2026-02-22T19:35:53.093Z+00:00
Explore related questions
See similar questions with these tags.


