[clang-tools-extra] r240938 - [clang-tidy] Fix false positives in the macro parentheses checker
Daniel Marjamaki
daniel.marjamaki at evidente.se
Mon Jun 29 05:18:11 PDT 2015
Author: danielmarjamaki
Date: Mon Jun 29 07:18:11 2015
New Revision: 240938
URL: http://llvm.org/viewvc/llvm-project?rev=240938&view=rev
Log:
[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
Modified:
clang-tools-extra/trunk/clang-tidy/misc/MacroParenthesesCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-macro-parentheses.cpp
Modified: clang-tools-extra/trunk/clang-tidy/misc/MacroParenthesesCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MacroParenthesesCheck.cpp?rev=240938&r1=240937&r2=240938&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/MacroParenthesesCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MacroParenthesesCheck.cpp Mon Jun 29 07:18:11 2015
@@ -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::argume
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::argume
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(), "(")
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-macro-parentheses.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-macro-parentheses.cpp?rev=240938&r1=240937&r2=240938&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-macro-parentheses.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-macro-parentheses.cpp Mon Jun 29 07:18:11 2015
@@ -32,6 +32,9 @@
#define GOOD20 void*
#define GOOD21(a) case Fred::a:
#define GOOD22(a) if (verbose) return a;
+#define GOOD23(type) (type::Field)
+#define GOOD24(t) std::set<t> s
+#define GOOD25(t) std::set<t,t,t> s
// These are allowed for now..
#define MAYBE1 *12.34
More information about the cfe-commits
mailing list