[clang-tools-extra] [clang-tidy] Add frames for bugprone-exception-escape options (PR #187971)

Zeyi Xu via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 28 04:20:47 PDT 2026


================
@@ -54,6 +60,29 @@ void call() noexcept {
   nothrow_nobody();
 }
 
+struct Member {
+  Member() noexcept {}
+  Member(const Member &) noexcept {}
+  Member &operator=(const Member &) noexcept { return *this; }
+  ~Member() noexcept {}
+};
+
+struct S {
+  // CHECK-MESSAGES-ALL: :[[@LINE-1]]:8: warning: an exception may be thrown in function 'S' which should not throw exceptions
+  // CHECK-MESSAGES-ALL: :[[@LINE-2]]:8: note: frame #0: an exception of unknown type may be thrown in function 'S' here
+  // CHECK-MESSAGES-ALL: :[[@LINE-3]]:8: warning: an exception may be thrown in function 'operator=' which should not throw exceptions
+  // CHECK-MESSAGES-ALL: :[[@LINE-4]]:8: note: frame #0: an exception of unknown type may be thrown in function 'operator=' here
+  // CHECK-MESSAGES-ALL: :[[@LINE-5]]:8: warning: an exception may be thrown in function '~S' which should not throw exceptions
+  // CHECK-MESSAGES-ALL: :[[@LINE-6]]:8: note: frame #0: an exception of unknown type may be thrown in function '~S' here
+  // CHECK-MESSAGES-UNDEFINED: :[[@LINE-7]]:8: warning: an exception may be thrown in function 'S' which should not throw exceptions
+  // CHECK-MESSAGES-UNDEFINED: :[[@LINE-8]]:8: note: frame #0: an exception of unknown type may be thrown in function 'S' here
+  // CHECK-MESSAGES-UNDEFINED: :[[@LINE-9]]:8: warning: an exception may be thrown in function 'operator=' which should not throw exceptions
+  // CHECK-MESSAGES-UNDEFINED: :[[@LINE-10]]:8: note: frame #0: an exception of unknown type may be thrown in function 'operator=' here
+  // CHECK-MESSAGES-UNDEFINED: :[[@LINE-11]]:8: warning: an exception may be thrown in function '~S' which should not throw exceptions
+  // CHECK-MESSAGES-UNDEFINED: :[[@LINE-12]]:8: note: frame #0: an exception of unknown type may be thrown in function '~S' here
----------------
zeyi2 wrote:

> This seems very wierd if we mark clearly non-throwing function (~S) as throwing, especially when ~Member() is noexcept

This is indeed a problem, but I think this should be fixed in a different PR. I added a `// FIXME` comment in the testcases. Is it okay to you?

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


More information about the cfe-commits mailing list