clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

ThrownExceptionTypeCheck.cpp
Go to the documentation of this file.
1 //===--- ThrownExceptionTypeCheck.cpp - clang-tidy-------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "ThrownExceptionTypeCheck.h"
11 #include "../utils/Matchers.h"
12 #include "clang/AST/ASTContext.h"
13 #include "clang/ASTMatchers/ASTMatchFinder.h"
14
15 using namespace clang::ast_matchers;
16
17 namespace clang {
18 namespace tidy {
19 namespace cert {
20
21 void ThrownExceptionTypeCheck::registerMatchers(MatchFinder *Finder) {
22 if (!getLangOpts().CPlusPlus)
23 return;
24
25 Finder->addMatcher(
26 cxxThrowExpr(
27 has(cxxConstructExpr(hasDeclaration(cxxConstructorDecl(
28 isCopyConstructor(), unless(isNoThrow()))))
29 .bind("expr"))),
30 this);
31 }
32
33 void ThrownExceptionTypeCheck::check(const MatchFinder::MatchResult &Result) {
34 const auto *E = Result.Nodes.getNodeAs<Expr>("expr");
35 diag(E->getExprLoc(),
36 "thrown exception type is not nothrow copy constructible");
37 }
38
39 } // namespace cert
40 } // namespace tidy
41 } // namespace clang
Finder
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:188
ThrownExceptionTypeCheck.h
Result
const NamedDecl * Result
Definition: USRFinder.cpp:121