clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

ThrowByValueCatchByReferenceCheck.h
Go to the documentation of this file.
1 //===--- ThrowByValueCatchByReferenceCheck.h - clang-tidy--------*- C++ -*-===//
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 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROW_BY_VALUE_CATCH_BY_REFERENCE_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROW_BY_VALUE_CATCH_BY_REFERENCE_H
12
13 #include "../ClangTidy.h"
14
15 namespace clang {
16 namespace tidy {
17
18 ///\brief checks for locations that do not throw by value
19 // or catch by reference.
20 // The check is C++ only. It checks that all throw locations
21 // throw by value and not by pointer. Additionally it
22 // contains an option ("CheckThrowTemporaries", default value "true") that
23 // checks that thrown objects are anonymous temporaries. It is also
24 // acceptable for this check to throw string literals.
25 // This test checks that exceptions are caught by reference
26 // and not by value or pointer. It will not warn when catching
27 // pointer to char, wchar_t, char16_t or char32_t. This is
28 // due to not warning on throwing string literals.
29 class ThrowByValueCatchByReferenceCheck : public ClangTidyCheck {
30 public:
31 ThrowByValueCatchByReferenceCheck(StringRef Name, ClangTidyContext *Context);
32 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
33 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
34 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
35
36 private:
37 void diagnoseThrowLocations(const CXXThrowExpr *throwExpr);
38 void diagnoseCatchLocations(const CXXCatchStmt *catchStmt,
39 ASTContext &context);
40 bool isFunctionParameter(const DeclRefExpr *declRefExpr);
41 bool isCatchVariable(const DeclRefExpr *declRefExpr);
42 bool isFunctionOrCatchVar(const DeclRefExpr *declRefExpr);
43 const bool CheckAnonymousTemporaries;
44 };
45
46 } // namespace tidy
47 } // namespace clang
48
49 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROW_BY_VALUE_CATCH_BY_REFERENCE_H
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
Finder
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:188
clang::tidy::ThrowByValueCatchByReferenceCheck
checks for locations that do not throw by value
Definition: ThrowByValueCatchByReferenceCheck.h:29
clang::tidy::ThrowByValueCatchByReferenceCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register ASTMatchers with Finder.
Definition: ThrowByValueCatchByReferenceCheck.cpp:25
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:102
clang::tidy::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:39
clang::tidy::ThrowByValueCatchByReferenceCheck::ThrowByValueCatchByReferenceCheck
ThrowByValueCatchByReferenceCheck(StringRef Name, ClangTidyContext *Context)
Definition: ThrowByValueCatchByReferenceCheck.cpp:20
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:82
Context
ClangTidyContext & Context
Definition: ClangTidy.cpp:93
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:124
clang::tidy::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:34
Result
const NamedDecl * Result
Definition: USRFinder.cpp:121