[clang-tidy] Fix misc-macro-repeated-side-effects false positive with stringified...
authorAlexander Kornienko <alexfh@google.com>
Sat, 23 Apr 2016 00:00:08 +0000 (00:00 +0000)
committerAlexander Kornienko <alexfh@google.com>
Sat, 23 Apr 2016 00:00:08 +0000 (00:00 +0000)
llvm-svn: 267254

clang-tools-extra/clang-tidy/misc/MacroRepeatedSideEffectsCheck.cpp
clang-tools-extra/test/clang-tidy/misc-macro-repeated-side-effects.c [moved from clang-tools-extra/test/clang-tidy/misc-repeated-side-effects-in-macro.c with 97% similarity]

index e8ad7c5..699966a 100644 (file)
@@ -86,6 +86,7 @@ unsigned MacroRepeatedPPCallbacks::countArgumentExpansions(
   int SkipParenCount = 0;
   // Has a __builtin_constant_p been found?
   bool FoundBuiltin = false;
+  bool PrevTokenIsHash = false;
   // Count when "?" is reached. The "Current" will get this value when the ":"
   // is reached.
   std::stack<unsigned, SmallVector<unsigned, 8>> CountAtQuestion;
@@ -98,6 +99,16 @@ unsigned MacroRepeatedPPCallbacks::countArgumentExpansions(
     if (FoundBuiltin && T.isOneOf(tok::question, tok::ampamp, tok::pipepipe))
       return Max;
 
+    // Skip stringified tokens.
+    if (T.is(tok::hash)) {
+      PrevTokenIsHash = true;
+      continue;
+    }
+    if (PrevTokenIsHash) {
+      PrevTokenIsHash = false;
+      continue;
+    }
+
     // Handling of ? and :.
     if (T.is(tok::question)) {
       CountAtQuestion.push(Current);