[clang-tools-extra] [clang-tidy] Add deprecated-posix-functions check (PR #195641)

Daniil Dudkin via cfe-commits cfe-commits at lists.llvm.org
Mon May 4 05:55:05 PDT 2026


================
@@ -0,0 +1,68 @@
+// RUN: %check_clang_tidy %s portability-deprecated-posix-functions %t
+
+typedef __SIZE_TYPE__ size_t;
+typedef int pid_t;
+typedef int uid_t;
+
+int bcmp(const void *S1, const void *S2, size_t N);
+void bcopy(const void *Src, void *Dest, size_t N);
+void bzero(void *S, size_t N);
+int getpw(uid_t UId, char *Buf);
+pid_t vfork(void);
+
+#define CALL_BZERO(Buffer, Size) bzero(Buffer, Size)
+#define DEPRECATED_BCMP bcmp
+
+void deprecated_posix_functions(void) {
+  char Buf1[128] = {0};
+  char Buf2[128] = {0};
+
+  bcmp(Buf1, Buf2, sizeof(Buf1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function 'bcmp' is deprecated; 'memcmp' should be used instead [portability-deprecated-posix-functions]
+
+  bcopy(Buf1, Buf2, sizeof(Buf1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function 'bcopy' is deprecated; 'memmove' should be used instead [portability-deprecated-posix-functions]
----------------
unterumarmung wrote:

```suggestion
  bcopy(Buf1, Buf2, sizeof(Buf1));
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function 'bcopy' is deprecated; 'memmove' should be used instead 
```

I think, a general suggestion is to drop check name after the first `CHECK` directive.


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


More information about the cfe-commits mailing list