clang-tools
22.0.0git
llvm-project
clang-tools-extra
clang-tidy
bugprone
MacroParenthesesCheck.h
Go to the documentation of this file.
1
//===----------------------------------------------------------------------===//
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::tidy::bugprone
{
15
16
/// Finds macros that can have unexpected behaviour due to missing parentheses.
17
///
18
/// Macros are expanded by the preprocessor as-is. As a result, there can be
19
/// unexpected behaviour; operators may be evaluated in unexpected order and
20
/// unary operators may become binary operators, etc.
21
///
22
/// When the replacement list has an expression, it is recommended to surround
23
/// it with parentheses. This ensures that the macro result is evaluated
24
/// completely before it is used.
25
///
26
/// It is also recommended to surround macro arguments in the replacement list
27
/// with parentheses. This ensures that the argument value is calculated
28
/// properly.
29
class
MacroParenthesesCheck
:
public
ClangTidyCheck
{
30
public
:
31
MacroParenthesesCheck
(StringRef Name,
ClangTidyContext
*Context)
32
:
ClangTidyCheck
(Name, Context) {}
33
void
registerPPCallbacks
(
const
SourceManager &SM, Preprocessor *
PP
,
34
Preprocessor *ModuleExpanderPP)
override
;
35
};
36
37
}
// namespace clang::tidy::bugprone
38
39
#endif
// LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MACROPARENTHESESCHECK_H
ClangTidyCheck.h
ClangTidyCheck
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition
ClangTidyDiagnosticConsumer.h:70
clang::tidy::bugprone::MacroParenthesesCheck::MacroParenthesesCheck
MacroParenthesesCheck(StringRef Name, ClangTidyContext *Context)
Definition
MacroParenthesesCheck.h:31
clang::tidy::bugprone::MacroParenthesesCheck::registerPPCallbacks
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Definition
MacroParenthesesCheck.cpp:264
clang::tidy::bugprone
Definition
ArgumentCommentCheck.cpp:19
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition
BadSignalToKillThreadCheck.cpp:28
Generated on
for clang-tools by
1.14.0