-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix #14634: Inconsistent AST for array declarations #8610
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -220,7 +220,8 @@ namespace ValueFlow | |
| void setTokenValue(Token* tok, | ||
| Value value, | ||
| const Settings& settings, | ||
| SourceLocation loc) | ||
| SourceLocation loc, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| bool recurseNamespaces) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we pass this as a flag? It is never set to false.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's set to false here: https://github.com/cppcheck-opensource/cppcheck/pull/8610/changes#diff-49c0f9d6942f6808cf091d306b42ae4639ff837acf2dcad90c28ed5c70cf850dR246. I wanted a way to propagate values both up and down namespace "stacks" without causing infinite recursion. I'm not super familiar with the value flow code though so there might be a better way. |
||
| { | ||
| // Skip setting values that are too big since its ambiguous | ||
| if (!value.isImpossible() && value.isIntValue() && value.intvalue < 0 && astIsUnsigned(tok) | ||
|
|
@@ -237,6 +238,14 @@ namespace ValueFlow | |
| if (!tok->addValue(value)) | ||
| return; | ||
|
|
||
| if (Token::simpleMatch(tok, "::") && recurseNamespaces) { | ||
| Token *inner = tok; | ||
| while (Token::simpleMatch(inner, "::")) | ||
| inner = inner->astOperand2(); | ||
| if (inner) | ||
| setTokenValue(inner, value, settings, SourceLocation::current(), false); | ||
| } | ||
|
|
||
| if (value.path < 0) | ||
| return; | ||
|
|
||
|
|
@@ -701,8 +710,8 @@ namespace ValueFlow | |
| } | ||
| } | ||
|
|
||
| else if (Token::Match(parent, ":: %name%") && parent->astOperand2() == tok) { | ||
| setTokenValue(parent, std::move(value), settings); | ||
| else if (Token::Match(parent, ":: %name%") && parent->astOperand2() == tok && recurseNamespaces) { | ||
| setTokenValue(parent, std::move(value), settings, SourceLocation::current(), false); | ||
| } | ||
|
|
||
| // Calling std::size or std::empty on an array | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.