clang-tools 22.0.0git
ThrownExceptionTypeCheck.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12
13using namespace clang::ast_matchers;
14
15namespace clang::tidy::cert {
16
18 Finder->addMatcher(
19 traverse(
20 TK_AsIs,
21 cxxThrowExpr(has(ignoringParenImpCasts(
22 cxxConstructExpr(hasDeclaration(cxxConstructorDecl(
23 isCopyConstructor(), unless(isNoThrow()))))
24 .bind("expr"))))),
25 this);
26}
27
28void ThrownExceptionTypeCheck::check(const MatchFinder::MatchResult &Result) {
29 const auto *E = Result.Nodes.getNodeAs<Expr>("expr");
30 diag(E->getExprLoc(),
31 "thrown exception type is not nothrow copy constructible");
32}
33
34} // namespace clang::tidy::cert
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
void registerMatchers(ast_matchers::MatchFinder *Finder) override