noexcept operator with lambdas. MSVC bug?

Viewed 163

It appears that MSVC treats all lambdas as noexcept. This code compiles in msvc 19.28 (checked in Compiler Explorer), but expectedly fails the static assertion in gcc:

void foo() {
  auto lambda_may_throw = [] {};

  static_assert(noexcept(lambda_may_throw()));
}

What is interesting is that I googled a bit but was unable to find any info on this issue. Is this really an msvc bug or just me failing to understand something?

1 Answers

The behavior is only observed with /permissive. When compiling with /permissive-, the assert triggers.

So perhaps it is a compatibility extension to support older Visual Studio code.

(You also may observe that it fails with /std:c++latest and compiles with /std:c++17 without specifying /permissive-. This is not the difference in standards, rather /std:c++latest also implies /permissive- by default)

Related