[clang] Do not trigger -Wmissing-noreturn on lambdas prior to C++23 (PR #154545)

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 20 08:06:42 PDT 2025


================
@@ -16,6 +17,16 @@ void throwError(const std::string& msg) { // expected-warning {{function 'throwE
   throw std::runtime_error(msg);
 }
 
+// We cannot use the [[noreturn]] attribute on lambdas until C++23
+void lambda(const std::string& msg) {
+#if __cplusplus >= 202302L
+  auto l1 = [&msg](){ throw std::runtime_error(msg); };  // expected-warning {{function 'operator()' could be declared with attribute 'noreturn'}}
+  auto l2 = [&msg] [[noreturn]] (){ throw std::runtime_error(msg); };
----------------
zwuis wrote:

Clang supports attributes here as languge extension before C++23. You can enable this test before C++23, and, disable the language extension warning or verify the warning is emitted.

https://github.com/llvm/llvm-project/pull/154545


More information about the cfe-commits mailing list