clang-tools 10.0.0

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
9 #include "ThrownExceptionTypeCheck.h"
10 #include "../utils/Matchers.h"
11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13
14 using namespace clang::ast_matchers;
15
16 namespace clang {
17 namespace tidy {
18 namespace cert {
19
20 void ThrownExceptionTypeCheck::registerMatchers(MatchFinder *Finder) {
21 if (!getLangOpts().CPlusPlus)
22 return;
23
24 Finder->addMatcher(
25 cxxThrowExpr(has(ignoringParenImpCasts(
26 cxxConstructExpr(hasDeclaration(cxxConstructorDecl(
27 isCopyConstructor(), unless(isNoThrow()))))
28 .bind("expr")))),
29 this);
30 }
31
32 void ThrownExceptionTypeCheck::check(const MatchFinder::MatchResult &Result) {
33 const auto *E = Result.Nodes.getNodeAs<Expr>("expr");
34 diag(E->getExprLoc(),
35 "thrown exception type is not nothrow copy constructible");
36 }
37
38 } // namespace cert
39 } // namespace tidy
40 } // namespace clang
clang::ast_matchers
Definition: AbseilMatcher.h:14
ThrownExceptionTypeCheck.h
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
E
const Expr * E
Definition: AvoidBindCheck.cpp:82