Skip to content

Commit e17af6d

Browse files
Report unknown macro (#4990)
1 parent 67a8ff0 commit e17af6d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/tokenize.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8095,8 +8095,12 @@ void Tokenizer::findGarbageCode() const
80958095
if (!isCPP() || mSettings->standards.cpp < Standards::CPP20 || !Token::Match(tok->previous(), "%name% : %num% ="))
80968096
syntaxError(tok, tok->next()->str() + " " + tok->strAt(2));
80978097
}
8098-
else if (Token::simpleMatch(tok, ") return") && !Token::Match(tok->link()->previous(), "if|while|for ("))
8099-
syntaxError(tok);
8098+
else if (Token::simpleMatch(tok, ") return") && !Token::Match(tok->link()->previous(), "if|while|for (")) {
8099+
if (tok->link()->previous() && tok->link()->previous()->isUpperCaseName())
8100+
unknownMacroError(tok->link()->previous());
8101+
else
8102+
syntaxError(tok);
8103+
}
81008104

81018105
if (tok->isControlFlowKeyword() && Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... }
81028106
if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|)")) {

test/testtokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6834,6 +6834,9 @@ class TestTokenizer : public TestFixture {
68346834
ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : 3 { };"), InternalError, "syntax error: Unexpected token '3'");
68356835

68366836
ASSERT_THROW_EQUALS(tokenizeAndStringify("int a() { b((c)return 0) }"), InternalError, "syntax error");
6837+
ASSERT_THROW_EQUALS(tokenizeAndStringify("int f() { MACRO(x) return 0; }"),
6838+
InternalError,
6839+
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");
68376840
}
68386841

68396842

0 commit comments

Comments
 (0)