Report unknown macro (#4990)
This commit is contained in:
parent
67a8ff0b27
commit
e17af6d2d8
|
@ -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%|:|;|{|}|)")) {
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue