[clang-tidy] Fix misc-macro-repeated-side-effects false positive with stringified arguments

llvm-svn: 267254
This commit is contained in:
Alexander Kornienko 2016-04-23 00:00:08 +00:00
parent 99ed605799
commit 5142c0d7fa
2 changed files with 16 additions and 0 deletions

View 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);

View File

@ -99,3 +99,8 @@ void conditionals(int a, int b)
condB(a, b++);
}
void log(const char *s, int v);
#define LOG(val) log(#val, (val))
void test_log(int a) {
LOG(a++);
}