clang-tools 10.0.0

SignedCharMisuseCheck.h
Go to the documentation of this file.
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 ``signed char`` -> integer conversions which might indicate a programming
19 /// error. The basic problem with the ``signed char``, that it might store the
20 /// non-ASCII characters as negative values. The human programmer probably
21 /// expects that after an integer conversion the converted value matches with the
22 /// character code (a value from [0..255]), however, the actual value is in
23 /// [-128..127] interval. This also applies to the plain ``char`` type on
24 /// those implementations which represent ``char`` similar to ``signed char``.
25 ///
26 /// For the user-facing documentation see:
27 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-signed-char-misuse.html
28 class SignedCharMisuseCheck : public ClangTidyCheck {
29 public:
30 SignedCharMisuseCheck(StringRef Name, ClangTidyContext *Context);
31
32 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
33 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
34 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
35
36 private:
37 const std::string CharTypdefsToIgnoreList;
38 };
39
40 } // namespace bugprone
41 } // namespace tidy
42 } // namespace clang
43
44 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIGNEDCHARMISUSECHECK_H
clang::tidy::bugprone::SignedCharMisuseCheck
Finds signed char -> integer conversions which might indicate a programming error.
Definition: SignedCharMisuseCheck.h:28
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:97
clang::tidy::bugprone::SignedCharMisuseCheck::SignedCharMisuseCheck
SignedCharMisuseCheck(StringRef Name, ClangTidyContext *Context)
Definition: SignedCharMisuseCheck.cpp:27
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::bugprone::SignedCharMisuseCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: SignedCharMisuseCheck.cpp:32
clang::tidy::bugprone::SignedCharMisuseCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: SignedCharMisuseCheck.cpp:36
clang::tidy::bugprone::SignedCharMisuseCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: SignedCharMisuseCheck.cpp:79
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77