clang-tools 22.0.0git
clang::tidy::bugprone::MacroParenthesesCheck Class Reference

Finds macros that can have unexpected behaviour due to missing parentheses. More...

#include <MacroParenthesesCheck.h>

Inheritance diagram for clang::tidy::bugprone::MacroParenthesesCheck:
[legend]

Public Member Functions

 MacroParenthesesCheck (StringRef Name, ClangTidyContext *Context)
void registerPPCallbacks (const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override

Detailed Description

Finds macros that can have unexpected behaviour due to missing parentheses.

Macros are expanded by the preprocessor as-is. As a result, there can be unexpected behaviour; operators may be evaluated in unexpected order and unary operators may become binary operators, etc.

When the replacement list has an expression, it is recommended to surround it with parentheses. This ensures that the macro result is evaluated completely before it is used.

It is also recommended to surround macro arguments in the replacement list with parentheses. This ensures that the argument value is calculated properly.

Definition at line 29 of file MacroParenthesesCheck.h.

Constructor & Destructor Documentation

◆ MacroParenthesesCheck()

clang::tidy::bugprone::MacroParenthesesCheck::MacroParenthesesCheck ( StringRef Name,
ClangTidyContext * Context )
inline

Definition at line 31 of file MacroParenthesesCheck.h.

Member Function Documentation

◆ registerPPCallbacks()

void clang::tidy::bugprone::MacroParenthesesCheck::registerPPCallbacks ( const SourceManager & SM,
Preprocessor * PP,
Preprocessor * ModuleExpanderPP )
override

Definition at line 264 of file MacroParenthesesCheck.cpp.

References clang::tidy::bugprone::PP.


The documentation for this class was generated from the following files: