I have a program that I would like to build in Visual Studio 2026, but struggle with the errors appearing.
One simplified piece of code is as follows:
void f(const void*) {}
int main() {
constexpr float one[1] = { 1.0f };
[&]() {
f(one);
f(&one[0]);
}();
}
- In
/std:c++17mode, MSVC accepts the program just fine. - In
/std:c++20mode, MSVC shows two errors:
<source>(6): error C2326: 'auto main::<lambda_1>::operator ()(void) const': function cannot access 'one'
<source>(7): error C2101: '&' on constant
- and in
/std:c++latestmode, it shows onlyerror C2101.
What changed in C++20 and later versions that caused the program to be rejected?
/std:c++17alone does not compile the code by the C++17 standard, it has an implicit/permissivewhich allows for Microsoft extensions. If you add/permissive-to the compile flags, the code won't compile. MSVC/std:c++20changed/permissive-(Microsoft extensions (mostly) disable) to be the default.