clang-tools
22.0.0git
llvm-project
clang-tools-extra
clang-tidy
bugprone
ExceptionCopyConstructorThrowsCheck.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
9
#include "
ExceptionCopyConstructorThrowsCheck.h
"
10
#include "clang/AST/ASTContext.h"
11
#include "clang/ASTMatchers/ASTMatchFinder.h"
12
13
using namespace
clang::ast_matchers
;
14
15
namespace
clang::tidy::bugprone
{
16
17
void
ExceptionCopyConstructorThrowsCheck::registerMatchers
(
18
MatchFinder *Finder) {
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
29
void
ExceptionCopyConstructorThrowsCheck::check
(
30
const
MatchFinder::MatchResult &Result) {
31
const
auto
*E = Result.Nodes.getNodeAs<Expr>(
"expr"
);
32
diag(E->getExprLoc(),
33
"thrown exception type is not nothrow copy constructible"
);
34
}
35
36
}
// namespace clang::tidy::bugprone
ExceptionCopyConstructorThrowsCheck.h
clang::tidy::bugprone::ExceptionCopyConstructorThrowsCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Definition
ExceptionCopyConstructorThrowsCheck.cpp:17
clang::tidy::bugprone::ExceptionCopyConstructorThrowsCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Definition
ExceptionCopyConstructorThrowsCheck.cpp:29
clang::ast_matchers
Definition
AbseilMatcher.h:16
clang::tidy::bugprone
Definition
ArgumentCommentCheck.cpp:19
Generated on
for clang-tools by
1.14.0