Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 1 | //===--- SignedCharMisuseCheck.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_BUGPRONE_SIGNEDCHARMISUSECHECK_H |
| 10 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIGNEDCHARMISUSECHECK_H |
| 11 | |
| 12 | #include "../ClangTidyCheck.h" |
| 13 | |
| 14 | namespace clang { |
| 15 | namespace tidy { |
| 16 | namespace bugprone { |
| 17 | |
| 18 | /// Finds those ``signed char`` -> integer conversions which might indicate a |
| 19 | /// programming error. The basic problem with the ``signed char``, that it might |
| 20 | /// store the non-ASCII characters as negative values. This behavior can cause a |
| 21 | /// misunderstanding of the written code both when an explicit and when an |
| 22 | /// implicit conversion happens. |
| 23 | /// |
| 24 | /// For the user-facing documentation see: |
| 25 | /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-signed-char-misuse.html |
| 26 | class SignedCharMisuseCheck : public ClangTidyCheck { |
| 27 | public: |
| 28 | SignedCharMisuseCheck(StringRef Name, ClangTidyContext *Context); |
| 29 | |
| 30 | void storeOptions(ClangTidyOptions::OptionMap &Opts) override; |
| 31 | void registerMatchers(ast_matchers::MatchFinder *Finder) override; |
| 32 | void check(const ast_matchers::MatchFinder::MatchResult &Result) override; |
| 33 | |
| 34 | private: |
| 35 | ast_matchers::internal::BindableMatcher<clang::Stmt> charCastExpression( |
| 36 | bool IsSigned, |
| 37 | const ast_matchers::internal::Matcher<clang::QualType> &IntegerType, |
| 38 | const std::string &CastBindName) const; |
| 39 | |
| 40 | const std::string CharTypdefsToIgnoreList; |
| 41 | const bool DiagnoseSignedUnsignedCharComparisons; |
| 42 | }; |
| 43 | |
| 44 | } // namespace bugprone |
| 45 | } // namespace tidy |
| 46 | } // namespace clang |
| 47 | |
| 48 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIGNEDCHARMISUSECHECK_H |