Tokenizer: Report unknown macro that contains '.x=..' argument

This commit is contained in:
Daniel Marjamäki 2020-04-04 10:32:56 +02:00
parent efb583e3d1
commit e0acd1abf8
2 changed files with 16 additions and 0 deletions

View File

@ -9337,6 +9337,19 @@ void Tokenizer::reportUnknownMacros()
}
}
// Report unknown macros that contain struct initialization "MACRO(a, .b=3)"
for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (!Token::Match(tok, "%name% ("))
continue;
const Token *endTok = tok->linkAt(1);
for (const Token *inner = tok->tokAt(2); inner != endTok; inner = inner->next()) {
if (Token::Match(inner, "[[({]"))
inner = inner->link();
else if (Token::Match(inner->previous(), "[,(] . %name% ="))
unknownMacroError(tok);
}
}
// Report unknown macros in non-executable scopes..
std::set<std::string> possible;
for (const Token *tok = tokens(); tok; tok = tok->next()) {

View File

@ -8002,6 +8002,9 @@ private:
" EVALUATE(123, int x=a; int y=b+c;);\n"
"}";
ASSERT_THROW(tokenizeAndStringify(code5), InternalError);
const char code6[] = "void foo() { dostuff(a, .x=0); }";
ASSERT_THROW(tokenizeAndStringify(code6), InternalError);
}
void findGarbageCode() { // Test Tokenizer::findGarbageCode()