clang-tools
18.0.0git
llvm-project
clang-tools-extra
clang-tidy
misc
ThrowByValueCatchByReferenceCheck.h
Go to the documentation of this file.
1
//===--- ThrowByValueCatchByReferenceCheck.h - clang-tidy--------*- C++ -*-===//
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
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROW_BY_VALUE_CATCH_BY_REFERENCE_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROW_BY_VALUE_CATCH_BY_REFERENCE_H
11
12
#include "../ClangTidyCheck.h"
13
14
namespace
clang::tidy::misc
{
15
16
///checks for locations that do not throw by value
17
// or catch by reference.
18
// The check is C++ only. It checks that all throw locations
19
// throw by value and not by pointer. Additionally it
20
// contains an option ("CheckThrowTemporaries", default value "true") that
21
// checks that thrown objects are anonymous temporaries. It is also
22
// acceptable for this check to throw string literals.
23
// This test checks that exceptions are caught by reference
24
// and not by value or pointer. It will not warn when catching
25
// pointer to char, wchar_t, char16_t or char32_t. This is
26
// due to not warning on throwing string literals.
27
class
ThrowByValueCatchByReferenceCheck
:
public
ClangTidyCheck
{
28
public
:
29
ThrowByValueCatchByReferenceCheck
(StringRef
Name
,
ClangTidyContext
*Context);
30
bool
isLanguageVersionSupported
(
const
LangOptions &LangOpts)
const override
{
31
return
LangOpts.CPlusPlus;
32
}
33
void
storeOptions
(
ClangTidyOptions::OptionMap
&Opts)
override
;
34
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
35
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
36
37
private
:
38
void
diagnoseThrowLocations(
const
CXXThrowExpr *ThrowExpr);
39
void
diagnoseCatchLocations(
const
CXXCatchStmt *CatchStmt,
40
ASTContext &Context);
41
bool
isFunctionParameter(
const
DeclRefExpr *DeclRefExpr);
42
bool
isCatchVariable(
const
DeclRefExpr *DeclRefExpr);
43
bool
isFunctionOrCatchVar(
const
DeclRefExpr *DeclRefExpr);
44
const
bool
CheckAnonymousTemporaries;
45
const
bool
WarnOnLargeObject;
46
const
uint64_t MaxSizeOptions;
// The raw value read from the options.
47
uint64_t MaxSize;
// No `const` because we have to set it in two steps.
48
};
49
50
}
// namespace clang::tidy::misc
51
52
#endif
// LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROW_BY_VALUE_CATCH_BY_REFERENCE_H
Name
llvm::StringRef Name
Definition:
HeaderIncludeCycleCheck.cpp:30
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:53
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:69
clang::tidy::misc::ThrowByValueCatchByReferenceCheck
checks for locations that do not throw by value
Definition:
ThrowByValueCatchByReferenceCheck.h:27
clang::tidy::misc::ThrowByValueCatchByReferenceCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
ThrowByValueCatchByReferenceCheck.cpp:28
clang::tidy::misc::ThrowByValueCatchByReferenceCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition:
ThrowByValueCatchByReferenceCheck.cpp:33
clang::tidy::misc::ThrowByValueCatchByReferenceCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
ThrowByValueCatchByReferenceCheck.cpp:40
clang::tidy::misc::ThrowByValueCatchByReferenceCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
Definition:
ThrowByValueCatchByReferenceCheck.h:30
clang::tidy::misc
Definition:
ConfusableIdentifierCheck.cpp:25
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition:
ClangTidyOptions.h:122
Generated on Thu Dec 7 2023 01:38:35 for clang-tools by
1.9.6