[clang-tools-extra] [clang-tidy] Add check 'bugprone-unsafe-to-allow-exceptions' (PR #176430)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 7 20:20:43 PST 2026
=?utf-8?q?Balázs_Kéri?= <balazs.keri at ericsson.com>,
=?utf-8?q?Balázs_Kéri?= <balazs.keri at ericsson.com>,
=?utf-8?q?Balázs_Kéri?= <balazs.keri at ericsson.com>,
=?utf-8?q?Balázs_Kéri?= <balazs.keri at ericsson.com>,
=?utf-8?q?Balázs_Kéri?= <balazs.keri at ericsson.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/176430 at github.com>
================
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 "UnsafeToAllowExceptionsCheck.h"
+
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/StringSet.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+namespace {
+
+AST_MATCHER_P(FunctionDecl, hasAnyName, llvm::StringSet<>, Names) {
+ return Names.contains(Node.getNameAsString());
+}
+
+AST_MATCHER(FunctionDecl, isExplicitThrow) {
+ return isExplicitThrowExceptionSpec(Node.getExceptionSpecType()) &&
+ Node.getExceptionSpecSourceRange().isValid();
+}
+
+} // namespace
+
+UnsafeToAllowExceptionsCheck::UnsafeToAllowExceptionsCheck(
+ StringRef Name, ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context),
+ RawCheckedSwapFunctions(
+ Options.get("CheckedSwapFunctions", "swap;iter_swap;iter_move")) {
+ llvm::SmallVector<StringRef, 4> CheckedSwapFunctionsVec;
+ RawCheckedSwapFunctions.split(CheckedSwapFunctionsVec, ";", -1, false);
+ CheckedSwapFunctions.insert_range(CheckedSwapFunctionsVec);
----------------
zwuis wrote:
How about changing the type of `CheckedSwapFunctions` to `SmallVector<StringRef>`, so that we can use `hasAnyName` matcher in ASTMatchers.h?
https://github.com/llvm/llvm-project/pull/176430
More information about the cfe-commits
mailing list