[PATCH] Clang-tidy macro parantheses checker, fix false positives for some c++ type usages

Daniel Marjamäki daniel.marjamaki at evidente.se
Mon Jun 29 04:41:49 PDT 2015


Hi alexfh,

This patch fix false positives, that alexfh pointed out, in the recently added clang-tidy macro parentheses checker.

http://reviews.llvm.org/D10801

Files:
  clang-tidy/misc/MacroParenthesesCheck.cpp
  test/clang-tidy/misc-macro-parentheses.cpp

Index: clang-tidy/misc/MacroParenthesesCheck.cpp
===================================================================
--- clang-tidy/misc/MacroParenthesesCheck.cpp
+++ clang-tidy/misc/MacroParenthesesCheck.cpp
@@ -151,6 +151,10 @@
     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,10 @@
     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(), "(")
Index: test/clang-tidy/misc-macro-parentheses.cpp
===================================================================
--- test/clang-tidy/misc-macro-parentheses.cpp
+++ test/clang-tidy/misc-macro-parentheses.cpp
@@ -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

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10801.28658.patch
Type: text/x-patch
Size: 1555 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150629/5165dc04/attachment.bin>


More information about the cfe-commits mailing list