================
@@ -0,0 +1,330 @@
+// RUN: %check_clang_tidy %s bugprone-null-check-after-dereference %t
+
+struct S {
+  int a;
+};
+
+int warning_deref(int *p) {
+  *p = 42;
+
+  if (p) {
+    // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: pointer value is checked even 
though it cannot be null at this point [bugprone-null-check-after-dereference]
+    // CHECK-MESSAGES: :[[@LINE-4]]:3: note: one of the locations where the 
pointer's value cannot be null
+  // FIXME: If there's a direct path, make the error message more precise, ie. 
remove `one of the locations`
+    *p += 20;
+    return *p;
----------------
martinboehme wrote:

Nit: This line seems to be redundant -- we already have a `*p` in the same 
block. Also, why does this function need to return anything -- just make it 
`void`?

(Generally, try to make tests contain only the minimal amount of code you need 
to test the behavior the test targets. Also applies similarly to other tests 
below.)

https://github.com/llvm/llvm-project/pull/84166
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to