SignedCharMisuseCheck.h 1.8 KB

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