Tokenizer; Report unknown macro used in function declaration
This commit is contained in:
parent
b8432b7e23
commit
900b99fbd8
|
@ -9309,6 +9309,7 @@ void Tokenizer::reportUnknownMacros()
|
|||
}
|
||||
|
||||
// Report unknown macros in non-executable scopes..
|
||||
std::set<std::string> possible;
|
||||
for (const Token *tok = tokens(); tok; tok = tok->next()) {
|
||||
// Skip executable scopes..
|
||||
if (tok->str() == "{") {
|
||||
|
@ -9317,7 +9318,10 @@ void Tokenizer::reportUnknownMacros()
|
|||
prev = prev->previous();
|
||||
if (prev && prev->str() == ")")
|
||||
tok = tok->link();
|
||||
}
|
||||
else
|
||||
possible.clear();
|
||||
} else if (tok->str() == "}")
|
||||
possible.clear();
|
||||
|
||||
if (Token::Match(tok, "%name% (") && tok->isUpperCaseName() && Token::simpleMatch(tok->linkAt(1), ") (") && Token::simpleMatch(tok->linkAt(1)->linkAt(1), ") {")) {
|
||||
// A keyword is not an unknown macro
|
||||
|
@ -9330,6 +9334,11 @@ void Tokenizer::reportUnknownMacros()
|
|||
if (Token::Match(tok2, "if|switch|for|while|return"))
|
||||
unknownMacroError(tok);
|
||||
}
|
||||
} else if (Token::Match(tok, "%name% (") && tok->isUpperCaseName() && Token::Match(tok->linkAt(1), ") %name% (") && Token::Match(tok->linkAt(1)->linkAt(2), ") [;{]")) {
|
||||
if (possible.count(tok->str()) == 0)
|
||||
possible.insert(tok->str());
|
||||
else
|
||||
unknownMacroError(tok);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7988,6 +7988,12 @@ private:
|
|||
|
||||
const char code3[] = "f(\"1\" __stringify(48) \"1\");";
|
||||
ASSERT_THROW(tokenizeAndStringify(code3), InternalError);
|
||||
|
||||
const char code4[] = "struct Foo {\n"
|
||||
" virtual MACRO(int) f1() {}\n"
|
||||
" virtual MACRO(int) f2() {}\n"
|
||||
"};";
|
||||
ASSERT_THROW(tokenizeAndStringify(code4), InternalError);
|
||||
}
|
||||
|
||||
void findGarbageCode() { // Test Tokenizer::findGarbageCode()
|
||||
|
|
Loading…
Reference in New Issue