UNSUPPORT test on 64-bit AIX too
[llvm-project.git] / clang-tools-extra / clang-tidy / misc / ThrowByValueCatchByReferenceCheck.h
blobde26b6ab5e0ad7b24f248d7df41ffe823f714c77
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 //===----------------------------------------------------------------------===//
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
12 #include "../ClangTidyCheck.h"
14 namespace clang {
15 namespace tidy {
16 namespace misc {
18 ///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 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
33 return LangOpts.CPlusPlus;
35 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
36 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
37 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
39 private:
40 void diagnoseThrowLocations(const CXXThrowExpr *ThrowExpr);
41 void diagnoseCatchLocations(const CXXCatchStmt *CatchStmt,
42 ASTContext &Context);
43 bool isFunctionParameter(const DeclRefExpr *DeclRefExpr);
44 bool isCatchVariable(const DeclRefExpr *DeclRefExpr);
45 bool isFunctionOrCatchVar(const DeclRefExpr *DeclRefExpr);
46 const bool CheckAnonymousTemporaries;
47 const bool WarnOnLargeObject;
48 const uint64_t MaxSizeOptions; // The raw value read from the options.
49 uint64_t MaxSize; // No `const` because we have to set it in two steps.
52 } // namespace misc
53 } // namespace tidy
54 } // namespace clang
56 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROW_BY_VALUE_CATCH_BY_REFERENCE_H