diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 925fe9c4a..1646c2029 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8095,8 +8095,12 @@ void Tokenizer::findGarbageCode() const if (!isCPP() || mSettings->standards.cpp < Standards::CPP20 || !Token::Match(tok->previous(), "%name% : %num% =")) syntaxError(tok, tok->next()->str() + " " + tok->strAt(2)); } - else if (Token::simpleMatch(tok, ") return") && !Token::Match(tok->link()->previous(), "if|while|for (")) - syntaxError(tok); + else if (Token::simpleMatch(tok, ") return") && !Token::Match(tok->link()->previous(), "if|while|for (")) { + if (tok->link()->previous() && tok->link()->previous()->isUpperCaseName()) + unknownMacroError(tok->link()->previous()); + else + syntaxError(tok); + } if (tok->isControlFlowKeyword() && Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... } if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|)")) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 69c447cc5..e7c5ec0a6 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6834,6 +6834,9 @@ private: ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : 3 { };"), InternalError, "syntax error: Unexpected token '3'"); ASSERT_THROW_EQUALS(tokenizeAndStringify("int a() { b((c)return 0) }"), InternalError, "syntax error"); + ASSERT_THROW_EQUALS(tokenizeAndStringify("int f() { MACRO(x) return 0; }"), + InternalError, + "There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it."); }