[clang] [clang] Check captured variables for noreturn attribute (PR #155213)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 25 06:43:13 PDT 2025


================
@@ -225,3 +225,16 @@ extern void abc_02(func_type *);
   abc_02(&func_ptr);
   func_ptr();
 } // expected-warning {{function declared 'noreturn' should not return}}
+
+[[noreturn]] void test_lambda() {
+  func_type func_ptr = noret;
+  [&func_ptr]() { func_ptr = ordinary; } ();
+  func_ptr();
+} // expected-warning {{function declared 'noreturn' should not return}}
+
+[[noreturn]] void test_lambda_var(int x) {
+  func_type func_ptr = noret;
+  auto LF = [&](){func_ptr = ordinary;};
----------------
erichkeane wrote:

Would like to see a test for member functions here as well.  Also, test that shows capture-by-value doesn't cause this diagnostic.

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


More information about the cfe-commits mailing list