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

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Wed May 6 07:23:24 PDT 2026


================
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "DeprecatedPosixFunctionsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/StringSwitch.h"
+
+using namespace clang::ast_matchers;
+using namespace llvm;
+
+namespace clang::tidy::portability {
+
+static constexpr StringRef DeprecatedFunctionId = "DeprecatedFunctions";
+static constexpr StringRef DeclRefId = "DRE";
+
+static StringRef getReplacementFor(StringRef FunctionName) {
+  // TODO: Suggest Annex K replacements when available.
+  return StringSwitch<StringRef>(FunctionName)
+      .Case("bcmp", "memcmp")
+      .Case("bcopy", "memmove")
+      .Case("bzero", "memset")
+      .Case("getpw", "getpwuid")
+      .Case("vfork", "posix_spawn")
+      .Default({});
----------------
zwuis wrote:

Use `DefaultUnreachable` or drop calling `Default`.

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


More information about the cfe-commits mailing list