clang-tools 20.0.0git
ThrownExceptionTypeCheck.cpp
Go to the documentation of this file.
1//===--- ThrownExceptionTypeCheck.cpp - clang-tidy-------------------------===//
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 "../utils/Matchers.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13
14using namespace clang::ast_matchers;
15
16namespace clang::tidy::cert {
17
19 Finder->addMatcher(
20 traverse(
21 TK_AsIs,
22 cxxThrowExpr(has(ignoringParenImpCasts(
23 cxxConstructExpr(hasDeclaration(cxxConstructorDecl(
24 isCopyConstructor(), unless(isNoThrow()))))
25 .bind("expr"))))),
26 this);
27}
28
29void ThrownExceptionTypeCheck::check(const MatchFinder::MatchResult &Result) {
30 const auto *E = Result.Nodes.getNodeAs<Expr>("expr");
31 diag(E->getExprLoc(),
32 "thrown exception type is not nothrow copy constructible");
33}
34
35} // namespace clang::tidy::cert
const Expr * E
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.