From b745d9ad6ec173640323b452cef6a182bc33bba0 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 22 Sep 2023 10:16:21 +0200 Subject: [PATCH] Fix #12010 Improve unknownMacro message: int (#5473) --- lib/tokenize.cpp | 6 +++--- test/testtokenize.cpp | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 01945aae5..af2323484 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8146,7 +8146,7 @@ static T* skipCPPOrAlignAttribute(T * tok) static bool isNonMacro(const Token* tok) { - if (tok->isKeyword()) + if (tok->isKeyword() || tok->isStandardType()) return true; if (cAlternativeTokens.count(tok->str()) > 0) return true; @@ -8272,7 +8272,7 @@ void Tokenizer::reportUnknownMacros() const for (const Token* tok = tokens(); tok; tok = tok->next()) { if (!Token::Match(tok, "%name% (")) continue; - if (isNonMacro(tok)) + if (isNonMacro(tok) && !tok->isStandardType()) continue; const Token* endTok = tok->linkAt(1); @@ -8288,7 +8288,7 @@ void Tokenizer::reportUnknownMacros() const continue; } - unknownMacroError(tok); + unknownMacroError(tok->isStandardType() ? tok2 : tok); } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 552a2a30b..3ac55383a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7043,6 +7043,10 @@ private: ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { MACRO(x(), y(), \"abc\", z(); ok = true); }\n"), // #12006 InternalError, "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."); }