Fix #15079 Regression: FP syntaxError for C-style cast before :: - #8912
chrchr-github wants to merge 1 commit into
Conversation
danmar
left a comment
There was a problem hiding this comment.
This is an AI review take it with a grain of salt. Please feel free to reject it by clicking on Resolve button
This fixes the same ticket as #8909 (autoantwort), which uses Token::Match(prev, "%name% (") && !prev->isKeyword() instead of prev->isNameOnly(). Both look correct. It might be good to agree on one and close the other. #8909 also has a few extra test cases that would be nice to have here: return (int)::abs(i); (a keyword before the cast), g((unsigned char)::toupper(i)); and decltype(s)::type i;.
| const Token* const prev = tok->linkAt(-1)->tokAt(-1); | ||
| if (!Token::Match(prev, "%name% (") || (!prev->isControlFlowKeyword() && prev->str() != "decltype")) { | ||
| if (prev && prev->isUpperCaseName()) | ||
| if (prev && prev->isNameOnly()) { |
There was a problem hiding this comment.
This is an AI review take it with a grain of salt. Please feel free to reject it by clicking on Resolve button
The old condition made the intent visible (%name% (, "something that looks like a macro call"). With isNameOnly() that's less obvious to a reader. A short comment would help, e.g. // NAME(...):: => NAME is probably an unknown macro; casts like (void)::f() and new (p) ::T are valid.
Note also that isNameOnly() is false for names with any extra flag set, so this is stricter than !prev->isKeyword(). That's fine from a no-false-positives point of view, just mentioning it in case it was unintentional.
| const Token* const prev = tok->linkAt(-1)->tokAt(-1); | ||
| if (!Token::Match(prev, "%name% (") || (!prev->isControlFlowKeyword() && prev->str() != "decltype")) { | ||
| if (prev && prev->isUpperCaseName()) | ||
| if (prev && prev->isNameOnly()) { |
There was a problem hiding this comment.
This is an AI review take it with a grain of salt. Please feel free to reject it by clicking on Resolve button
Whether a token is a keyword depends on --std (TokenList::isKeyword() uses Keywords::getAll(standards.cpp)). With --std=c++03, decltype is a plain name with no other flags, so isNameOnly() is true and this gives a false syntaxError (verified with the same condition in #8909):
$ cppcheck --std=c++03 dt.cpp
dt.cpp:3:12: error: syntax error [syntaxError]
decltype(s)::type i;
The old code avoided this with prev->str() != "decltype". Maybe keep that, e.g. if (prev && prev->isNameOnly() && prev->str() != "decltype").
|
Closing in favor of #8909 |
No description provided.