Tokenizer: detect unknown macro 'if (x) MACRO }' (#5209)
This commit is contained in:
parent
59a8944e30
commit
96955ccfe9
|
@ -8054,6 +8054,17 @@ void Tokenizer::reportUnknownMacros() const
|
|||
}
|
||||
}
|
||||
|
||||
// Report unknown macros before } "{ .. if (x) MACRO }"
|
||||
for (const Token *tok = tokens(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, ")|; %name% }")) {
|
||||
const Token* prev = tok->linkAt(2);
|
||||
while (Token::simpleMatch(prev, "{"))
|
||||
prev = prev->previous();
|
||||
if (Token::Match(prev, ";|)"))
|
||||
unknownMacroError(tok->next());
|
||||
}
|
||||
}
|
||||
|
||||
// Report unknown macros that contain several statements "MACRO(a;b;c)"
|
||||
for (const Token *tok = tokens(); tok; tok = tok->next()) {
|
||||
if (!Token::Match(tok, "%name% ("))
|
||||
|
|
|
@ -6843,6 +6843,9 @@ private:
|
|||
ASSERT_NO_THROW(tokenizeAndStringify(code11));
|
||||
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("alignas(8) alignas(16) int x;")); // alignas is not unknown macro
|
||||
|
||||
ASSERT_THROW(tokenizeAndStringify("void foo() { if(x) SYSTEM_ERROR }"), InternalError);
|
||||
ASSERT_THROW(tokenizeAndStringify("void foo() { dostuff(); SYSTEM_ERROR }"), InternalError);
|
||||
}
|
||||
|
||||
void findGarbageCode() { // Test Tokenizer::findGarbageCode()
|
||||
|
|
Loading…
Reference in New Issue