aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.cpp
new file mode 100644
index 0000000..7365845
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 "ExceptionCopyConstructorThrowsCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void ExceptionCopyConstructorThrowsCheck::registerMatchers(
+ MatchFinder *Finder) {
+ Finder->addMatcher(
+ traverse(
+ TK_AsIs,
+ cxxThrowExpr(has(ignoringParenImpCasts(
+ cxxConstructExpr(hasDeclaration(cxxConstructorDecl(
+ isCopyConstructor(), unless(isNoThrow()))))
+ .bind("expr"))))),
+ this);
+}
+
+void ExceptionCopyConstructorThrowsCheck::check(
+ const MatchFinder::MatchResult &Result) {
+ const auto *E = Result.Nodes.getNodeAs<Expr>("expr");
+ diag(E->getExprLoc(),
+ "thrown exception type is not nothrow copy constructible");
+}
+
+} // namespace clang::tidy::bugprone