diff options
author | Daniel Marjamaki <daniel.marjamaki@evidente.se> | 2015-06-29 12:18:11 +0000 |
---|---|---|
committer | Daniel Marjamaki <daniel.marjamaki@evidente.se> | 2015-06-29 12:18:11 +0000 |
commit | 4a38b0b493643a5db66bd7c6eaf2a42f1a9f67bd (patch) | |
tree | c9c6e0519b16c9c510462c0cbc94d375e30430ce /clang-tools-extra/clang-tidy/misc/MacroParenthesesCheck.cpp | |
parent | 4002ce483477c9bb099d3e2bcf0ea3f392b57ad4 (diff) | |
download | bcm5719-llvm-4a38b0b493643a5db66bd7c6eaf2a42f1a9f67bd.tar.gz bcm5719-llvm-4a38b0b493643a5db66bd7c6eaf2a42f1a9f67bd.zip |
[clang-tidy] Fix false positives in the macro parentheses checker
Summary:
There were false positives in C++ code where macro argument was a type.
Reviewers: alexfh
Differential Revision: http://reviews.llvm.org/D10801
llvm-svn: 240938
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/MacroParenthesesCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/misc/MacroParenthesesCheck.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/MacroParenthesesCheck.cpp b/clang-tools-extra/clang-tidy/misc/MacroParenthesesCheck.cpp index 7d5aca43f58..68997ede2db 100644 --- a/clang-tools-extra/clang-tidy/misc/MacroParenthesesCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/MacroParenthesesCheck.cpp @@ -59,8 +59,8 @@ bool isKeyword(const Token &T) { /// Warning is written when one of these operators are not within parentheses. bool isWarnOp(const Token &T) { - /// \TODO This is an initial list of operators. It can be tweaked later to - /// get more positives or perhaps avoid some false positive. + /// \TODO This is an initial list of operators. It can be tweaked later to + /// get more positives or perhaps avoid some false positive. return T.isOneOf(tok::plus, tok::minus, tok::star, tok::slash, tok::percent, tok::amp, tok::pipe, tok::caret); } @@ -151,6 +151,10 @@ void MacroParenthesesPPCallbacks::argument(const Token &MacroNameTok, if (Prev.isOneOf(tok::period, tok::arrow, tok::coloncolon)) continue; + // Argument is a namespace or class. + if (Next.is(tok::coloncolon)) + continue; + // String concatenation. if (isStringLiteral(Prev.getKind()) || isStringLiteral(Next.getKind())) continue; @@ -173,6 +177,11 @@ void MacroParenthesesPPCallbacks::argument(const Token &MacroNameTok, if (Prev.isOneOf(tok::equal, tok::kw_return) && Next.is(tok::semi)) continue; + // C++ template parameters. + if (PP->getLangOpts().CPlusPlus && Prev.isOneOf(tok::comma, tok::less) && + Next.isOneOf(tok::comma, tok::greater)) + continue; + Check->diag(Tok.getLocation(), "macro argument should be enclosed in " "parentheses") << FixItHint::CreateInsertion(Tok.getLocation(), "(") |