Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #13378: syntax error for guessed macro value #7218

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8729,10 +8729,16 @@ void Tokenizer::findGarbageCode() const
if (Token::Match(tok, "%num%|%bool%|%char%|%str% %num%|%bool%|%char%|%str%") && !Token::Match(tok, "%str% %str%"))
syntaxError(tok);
if (Token::Match(tok, "%num%|%bool%|%char%|%str% {|(")) {
if (tok->strAt(1) == "(")
if (tok->strAt(1) == "(") {
if (tok->isExpandedMacro() && mSettings.userDefines.empty()) {
throw InternalError(tok, "literal used as function. Macro '" + tok->getMacroName() +
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my goal would be that this message is only written if the macro is defined by Preprocessor::getConfigs => that means the macro value is guessed by Cppcheck.

The configuration is passed to Tokenizer::simplifyTokens1. Can that be propagated here so that we can check if it contains the macro name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the configuration is overriden by CLI/project defines by then already:

mCurrentConfig = mSettings.userDefines;

But that only happens if mSettings.userDefines is empty, so I think it should be enough to check the same condition in findGarbageCode.

"' expands to '" + tok->str() + +"'. Use -D" + tok->getMacroName() +
"=... to specify a value, or -U" + tok->getMacroName()
+ " to undefine it.", InternalError::UNKNOWN_MACRO);
}
syntaxError(tok);
else if (!(tok->tokType() == Token::Type::eString && Token::simpleMatch(tok->tokAt(-1), "extern")) &&
!(tok->tokType() == Token::Type::eBoolean && cpp && Token::simpleMatch(tok->tokAt(-1), "requires")))
} else if (!(tok->tokType() == Token::Type::eString && Token::simpleMatch(tok->tokAt(-1), "extern")) &&
!(tok->tokType() == Token::Type::eBoolean && cpp && Token::simpleMatch(tok->tokAt(-1), "requires")))
syntaxError(tok);
}
if (Token::Match(tok, "( ) %num%|%bool%|%char%|%str%"))
Expand Down
Loading