clang-tools 10.0.0

MacroParenthesesCheck.h
Go to the documentation of this file.
1 //===--- MacroParenthesesCheck.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_MACROPARENTHESESCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MACROPARENTHESESCHECK_H
11
12 #include "../ClangTidyCheck.h"
13
14 namespace clang {
15 namespace tidy {
16 namespace bugprone {
17
18 /// Finds macros that can have unexpected behaviour due to missing parentheses.
19 ///
20 /// Macros are expanded by the preprocessor as-is. As a result, there can be
21 /// unexpected behaviour; operators may be evaluated in unexpected order and
22 /// unary operators may become binary operators, etc.
23 ///
24 /// When the replacement list has an expression, it is recommended to surround
25 /// it with parentheses. This ensures that the macro result is evaluated
26 /// completely before it is used.
27 ///
28 /// It is also recommended to surround macro arguments in the replacement list
29 /// with parentheses. This ensures that the argument value is calculated
30 /// properly.
31 class MacroParenthesesCheck : public ClangTidyCheck {
32 public:
33 MacroParenthesesCheck(StringRef Name, ClangTidyContext *Context)
34 : ClangTidyCheck(Name, Context) {}
35 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
36 Preprocessor *ModuleExpanderPP) override;
37 };
38
39 } // namespace bugprone
40 } // namespace tidy
41 } // namespace clang
42
43 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MACROPARENTHESESCHECK_H
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
clang::tidy::bugprone::MacroParenthesesCheck::MacroParenthesesCheck
MacroParenthesesCheck(StringRef Name, ClangTidyContext *Context)
Definition: MacroParenthesesCheck.h:33
clang::tidy::bugprone::MacroParenthesesCheck
Finds macros that can have unexpected behaviour due to missing parentheses.
Definition: MacroParenthesesCheck.h:31
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition: BadSignalToKillThreadCheck.cpp:28
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77
clang::tidy::bugprone::MacroParenthesesCheck::registerPPCallbacks
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
Definition: MacroParenthesesCheck.cpp:251