blob: 84d3bbbf4e7643ad42acbf1c7fd0d7653b8c75fc [file] [log] [blame]
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02001//===--- 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
14namespace clang {
15namespace tidy {
16namespace 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
26class SignedCharMisuseCheck : public ClangTidyCheck {
27public:
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
34private:
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