[clang] [WebKit checkers] Disallow operator delete in a trivial context. (PR #185122)

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 6 15:09:23 PST 2026


================
@@ -70,6 +70,27 @@ void [[clang::annotate_type("webkit.nodelete")]] callsUnsafe() {
   someFunction(); // expected-warning{{A function 'callsUnsafe' has [[clang::annotate_type("webkit.nodelete")]] but it contains code that could destruct an object}}
 }
 
+int* [[clang::annotate_type("webkit.nodelete")]] createsInt() {
+  return new int;
+}
+
+void [[clang::annotate_type("webkit.nodelete")]] destroysInt(int* number) {
+  delete number; // expected-warning{{A function 'destroysInt' has [[clang::annotate_type("webkit.nodelete")]] but it contains code that could destruct an object}}
----------------
steakhal wrote:

Does a test case work the same way if you directly call `::operator delete(number);`?

I bet it wouldnt catch it.

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


More information about the cfe-commits mailing list