Fix #15079 FP syntaxError for C-style cast before scope operator - #8909
Open
autoantwort wants to merge 1 commit into
Open
autoantwort wants to merge 1 commit into
autoantwort wants to merge 1 commit into
Conversation
The check added in a294079 (#15060) reports every `)` followed by `::` unless the `(` belongs to a control flow keyword or decltype. That also rejects valid code like `(HWND)::SendMessage(...)` or placement new `new (p) ::N::T`, so whole translation units are skipped. Only report when the parenthesis follows a non-keyword name, which is the unknown macro case the check was added for. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
danmar
reviewed
Oct 2, 2026
| const Token* const prev = tok->linkAt(-1)->tokAt(-1); | ||
| if (!Token::Match(prev, "%name% (") || (!prev->isControlFlowKeyword() && prev->str() != "decltype")) { | ||
| if (prev && prev->isUpperCaseName()) | ||
| if (Token::Match(prev, "%name% (") && !prev->isKeyword()) { |
Collaborator
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, so this now gives a false syntaxError:
$ 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. && !prev->isKeyword() && prev->str() != "decltype".
| " *p = -*p;\n" | ||
| "}\n")); | ||
|
|
||
| ASSERT_NO_THROW(tokenizeAndStringify("void f(void* h) {\n" // cast before global scope operator |
Collaborator
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
In this project tests usually reference the ticket number, e.g. // #15079.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://trac.cppcheck.net/ticket/15079
The check added in a294079 (#15060) reports every
)followed by::unless the(belongs to a control flow keyword ordecltype. That also rejects valid code, and the whole file is skipped:Now the error is only reported when the parenthesis follows a non-keyword name, the unknown macro case (
CL_NS(util)::X,void C(abc)::f()) the check was added for.On our code base this regression dropped the number of findings from 17401 to 9193 (10 files with casts like the ones above, one of them a widely included header). With this change the count is back to the previous level.
This PR was created by Claude Code (an AI coding agent) on behalf of @autoantwort.
🤖 Generated with Claude Code