Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:20

0001 //===--- ThrowByValueCatchByReferenceCheck.h - clang-tidy--------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROW_BY_VALUE_CATCH_BY_REFERENCE_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROW_BY_VALUE_CATCH_BY_REFERENCE_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 
0014 namespace clang::tidy::misc {
0015 
0016 ///checks for locations that do not throw by value
0017 // or catch by reference.
0018 // The check is C++ only. It checks that all throw locations
0019 // throw by value and not by pointer. Additionally it
0020 // contains an option ("CheckThrowTemporaries", default value "true") that
0021 // checks that thrown objects are anonymous temporaries. It is also
0022 // acceptable for this check to throw string literals.
0023 // This test checks that exceptions are caught by reference
0024 // and not by value or pointer. It will not warn when catching
0025 // pointer to char, wchar_t, char16_t or char32_t. This is
0026 // due to not warning on throwing string literals.
0027 class ThrowByValueCatchByReferenceCheck : public ClangTidyCheck {
0028 public:
0029   ThrowByValueCatchByReferenceCheck(StringRef Name, ClangTidyContext *Context);
0030   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
0031     return LangOpts.CPlusPlus;
0032   }
0033   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0034   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0035   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0036 
0037 private:
0038   void diagnoseThrowLocations(const CXXThrowExpr *ThrowExpr);
0039   void diagnoseCatchLocations(const CXXCatchStmt *CatchStmt,
0040                               ASTContext &Context);
0041   bool isFunctionParameter(const DeclRefExpr *DeclRefExpr);
0042   bool isCatchVariable(const DeclRefExpr *DeclRefExpr);
0043   bool isFunctionOrCatchVar(const DeclRefExpr *DeclRefExpr);
0044   const bool CheckAnonymousTemporaries;
0045   const bool WarnOnLargeObject;
0046   const uint64_t MaxSizeOptions; // The raw value read from the options.
0047   uint64_t MaxSize; // No `const` because we have to set it in two steps.
0048 };
0049 
0050 } // namespace clang::tidy::misc
0051 
0052 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROW_BY_VALUE_CATCH_BY_REFERENCE_H