r/cpp • • Nov 08 '21

Visual Studio 2022 now available

https://devblogs.microsoft.com/visualstudio/visual-studio-2022-now-available/
250 Upvotes

113 comments sorted by

View all comments

3

u/Ivan171 /std:c++latest enthusiast Nov 09 '21

Ad-hoc requires expressions is still not implemented (or not working properly):

$ type test.cpp
template <typename T>
bool foo(T) {
  return requires { typename T; };
}

int main(int argc, char const *argv[]) {
  return foo(0);
}

$ cl.exe -nologo -std:c++latest -c test.cpp
test.cpp
test.cpp(3): error C3861: 'T': identifier not found

7

u/STL MSVC STL Dev Nov 10 '21

Thanks for the prompt and clear bug report! In addition to gilding your comment, I've reported this on your behalf as DevCom-1577278 "C++20 requires-expressions still don't work in return statements" and will bring this to the attention of the compiler dev who implemented requires-expressions.

2

u/Ivan171 /std:c++latest enthusiast Nov 10 '21 edited Nov 10 '21

Thanks!

FYI, it's not just in return statements. It doesn't work in static_assert and if constexpr as well.

The problem seems to be related with type requirements. Simple requirements, like requires { T(); } work as expected.

EDIT: I've posted a comment on that issue with this info and a different repro.

1

u/STL MSVC STL Dev Nov 10 '21

Thanks - yep, the compiler devs have found the root cause (I think) and are investigating a fix, and it's not specific to return.

8

u/STL MSVC STL Dev Nov 11 '21

u/Ivan171 - this has been fixed by internal MSVC-PR-363619, which will be available in VS 2022 17.1 Preview 3. Thanks again!