Daniel Marjamaki | 302275a | 2015-06-16 14:27:31 +0000 | [diff] [blame] | 1 | //===--- MacroParenthesesCheck.h - clang-tidy--------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MACRO_PARENTHESES_H |
| 11 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MACRO_PARENTHESES_H |
| 12 | |
| 13 | #include "../ClangTidy.h" |
| 14 | |
| 15 | namespace clang { |
| 16 | namespace tidy { |
Etienne Bergeron | 456177b | 2016-05-02 18:00:29 +0000 | [diff] [blame] | 17 | namespace misc { |
Daniel Marjamaki | 302275a | 2015-06-16 14:27:31 +0000 | [diff] [blame] | 18 | |
Alexander Kornienko | f8ed0a8 | 2015-08-27 18:01:58 +0000 | [diff] [blame] | 19 | /// Finds macros that can have unexpected behaviour due to missing parentheses. |
Daniel Marjamaki | 302275a | 2015-06-16 14:27:31 +0000 | [diff] [blame] | 20 | /// |
| 21 | /// Macros are expanded by the preprocessor as-is. As a result, there can be |
| 22 | /// unexpected behaviour; operators may be evaluated in unexpected order and |
| 23 | /// unary operators may become binary operators, etc. |
| 24 | /// |
| 25 | /// When the replacement list has an expression, it is recommended to surround |
| 26 | /// it with parentheses. This ensures that the macro result is evaluated |
| 27 | /// completely before it is used. |
| 28 | /// |
| 29 | /// It is also recommended to surround macro arguments in the replacement list |
| 30 | /// with parentheses. This ensures that the argument value is calculated |
| 31 | /// properly. |
| 32 | class MacroParenthesesCheck : public ClangTidyCheck { |
| 33 | public: |
| 34 | MacroParenthesesCheck(StringRef Name, ClangTidyContext *Context) |
| 35 | : ClangTidyCheck(Name, Context) {} |
| 36 | void registerPPCallbacks(CompilerInstance &Compiler) override; |
| 37 | }; |
| 38 | |
Etienne Bergeron | 456177b | 2016-05-02 18:00:29 +0000 | [diff] [blame] | 39 | } // namespace misc |
Daniel Marjamaki | 302275a | 2015-06-16 14:27:31 +0000 | [diff] [blame] | 40 | } // namespace tidy |
| 41 | } // namespace clang |
| 42 | |
| 43 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MACRO_PARENTHESES_H |