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 "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12
13using namespace clang::ast_matchers;
14
15namespace clang::tidy::cert {
16
17void ThrownExceptionTypeCheck::registerMatchers(MatchFinder *Finder) {
18 Finder->addMatcher(
19 NodeMatch: traverse(
20 TK: TK_AsIs,
21 InnerMatcher: cxxThrowExpr(has(ignoringParenImpCasts(
22 InnerMatcher: cxxConstructExpr(hasDeclaration(InnerMatcher: cxxConstructorDecl(
23 isCopyConstructor(), unless(isNoThrow()))))
24 .bind(ID: "expr"))))),
25 Action: this);
26}
27
28void ThrownExceptionTypeCheck::check(const MatchFinder::MatchResult &Result) {
29 const auto *E = Result.Nodes.getNodeAs<Expr>(ID: "expr");
30 diag(Loc: E->getExprLoc(),
31 Description: "thrown exception type is not nothrow copy constructible");
32}
33
34} // namespace clang::tidy::cert
35

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.cpp