2015-06-16 22:27:31 +08:00
|
|
|
//===--- MacroParenthesesCheck.h - clang-tidy--------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-06-16 22:27:31 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-03-15 16:25:39 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MACROPARENTHESESCHECK_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MACROPARENTHESESCHECK_H
|
2015-06-16 22:27:31 +08:00
|
|
|
|
2019-03-25 20:38:26 +08:00
|
|
|
#include "../ClangTidyCheck.h"
|
2015-06-16 22:27:31 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
2018-03-15 16:25:39 +08:00
|
|
|
namespace bugprone {
|
2015-06-16 22:27:31 +08:00
|
|
|
|
2015-08-28 02:01:58 +08:00
|
|
|
/// Finds macros that can have unexpected behaviour due to missing parentheses.
|
2015-06-16 22:27:31 +08:00
|
|
|
///
|
|
|
|
/// 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.
|
|
|
|
class MacroParenthesesCheck : public ClangTidyCheck {
|
|
|
|
public:
|
|
|
|
MacroParenthesesCheck(StringRef Name, ClangTidyContext *Context)
|
|
|
|
: ClangTidyCheck(Name, Context) {}
|
2019-03-23 02:58:12 +08:00
|
|
|
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
|
|
|
|
Preprocessor *ModuleExpanderPP) override;
|
2015-06-16 22:27:31 +08:00
|
|
|
};
|
|
|
|
|
2018-03-15 16:25:39 +08:00
|
|
|
} // namespace bugprone
|
2015-06-16 22:27:31 +08:00
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|
|
|
|
|
2018-03-15 16:25:39 +08:00
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MACROPARENTHESESCHECK_H
|