[clang] [analyzer] MallocChecker – Fix false positive leak for smart pointers in temporary objects (PR #152751)

Donát Nagy via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 2 06:50:05 PDT 2025


================
@@ -187,12 +202,12 @@ void test_variadic_constructor_bounds() {
   // The constructor has 1 formal parameter (T* p) plus ellipsis, but we pass multiple args
   // This should trigger the bounds checking issue in handleSmartPointerConstructorArguments
   int* raw_ptr = new int(42);
-  process_variadic_smart_ptr(VariadicSmartPtr<int>(raw_ptr, 1, 2, 3, 4, 5));
+  process_variadic_smart_ptr(unique_ptr<int>(raw_ptr, 1, 2, 3, 4, 5));
   
   (void)malloc_ptr;
 } // expected-warning {{Potential leak of memory pointed to by 'malloc_ptr'}} expected-note {{Potential leak of memory pointed to by 'malloc_ptr'}}
----------------
NagyDonat wrote:

```suggestion
} // expected-warning {{Potential leak of memory pointed to by 'malloc_ptr'}}
  // expected-note at -1 {{Potential leak of memory pointed to by 'malloc_ptr'}}
```
It is possible to move an `expected-` markers onto a different line (by adding `@` + relative line number) and it may be a nice touch on long lines like this.

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


More information about the cfe-commits mailing list