Skip to content

Commit c305f4a

Browse files
committed
add message for expanded macro leading to invalid syntax
1 parent b901fbe commit c305f4a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/tokenize.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -8729,10 +8729,16 @@ void Tokenizer::findGarbageCode() const
87298729
if (Token::Match(tok, "%num%|%bool%|%char%|%str% %num%|%bool%|%char%|%str%") && !Token::Match(tok, "%str% %str%"))
87308730
syntaxError(tok);
87318731
if (Token::Match(tok, "%num%|%bool%|%char%|%str% {|(")) {
8732-
if (tok->strAt(1) == "(")
8732+
if (tok->strAt(1) == "(") {
8733+
if (tok->isExpandedMacro() && mSettings.userDefines.empty()) {
8734+
throw InternalError(tok, "literal used as function. Macro '" + tok->getMacroName() +
8735+
"' expands to '" + tok->str() + +"'. Use -D" + tok->getMacroName() +
8736+
"=... to specify a value, or -U" + tok->getMacroName()
8737+
+ " to undefine it.", InternalError::UNKNOWN_MACRO);
8738+
}
87338739
syntaxError(tok);
8734-
else if (!(tok->tokType() == Token::Type::eString && Token::simpleMatch(tok->tokAt(-1), "extern")) &&
8735-
!(tok->tokType() == Token::Type::eBoolean && cpp && Token::simpleMatch(tok->tokAt(-1), "requires")))
8740+
} else if (!(tok->tokType() == Token::Type::eString && Token::simpleMatch(tok->tokAt(-1), "extern")) &&
8741+
!(tok->tokType() == Token::Type::eBoolean && cpp && Token::simpleMatch(tok->tokAt(-1), "requires")))
87368742
syntaxError(tok);
87378743
}
87388744
if (Token::Match(tok, "( ) %num%|%bool%|%char%|%str%"))

0 commit comments

Comments
 (0)