Fix #12010 Improve unknownMacro message: int (#5473)

This commit is contained in:
chrchr-github 2023-09-22 10:16:21 +02:00 committed by GitHub
parent 6fcf11b831
commit b745d9ad6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -8146,7 +8146,7 @@ static T* skipCPPOrAlignAttribute(T * tok)
static bool isNonMacro(const Token* tok) static bool isNonMacro(const Token* tok)
{ {
if (tok->isKeyword()) if (tok->isKeyword() || tok->isStandardType())
return true; return true;
if (cAlternativeTokens.count(tok->str()) > 0) if (cAlternativeTokens.count(tok->str()) > 0)
return true; return true;
@ -8272,7 +8272,7 @@ void Tokenizer::reportUnknownMacros() const
for (const Token* tok = tokens(); tok; tok = tok->next()) { for (const Token* tok = tokens(); tok; tok = tok->next()) {
if (!Token::Match(tok, "%name% (")) if (!Token::Match(tok, "%name% ("))
continue; continue;
if (isNonMacro(tok)) if (isNonMacro(tok) && !tok->isStandardType())
continue; continue;
const Token* endTok = tok->linkAt(1); const Token* endTok = tok->linkAt(1);
@ -8288,7 +8288,7 @@ void Tokenizer::reportUnknownMacros() const
continue; continue;
} }
unknownMacroError(tok); unknownMacroError(tok->isStandardType() ? tok2 : tok);
} }
} }

View File

@ -7043,6 +7043,10 @@ private:
ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { MACRO(x(), y(), \"abc\", z(); ok = true); }\n"), // #12006 ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { MACRO(x(), y(), \"abc\", z(); ok = true); }\n"), // #12006
InternalError, InternalError,
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it."); "There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");
ASSERT_THROW_EQUALS(tokenizeAndStringify("int (*f) MACRO((void *));\n"), // #12010
InternalError,
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");
} }