-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix #14782: Partially or fully missing valuetype info for auto declarations #8599
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 |
|---|---|---|
|
|
@@ -7017,6 +7017,10 @@ | |
| setAutoTokenProperties(autoTok); | ||
| if (vt2->pointer > vt.pointer) | ||
| vt.pointer++; | ||
| if (Token::simpleMatch(autoTok->next(), "&")) | ||
| vt.reference = Reference::LValue; | ||
| if (Token::simpleMatch(autoTok->next(), "&&")) | ||
| vt.reference = Reference::RValue; | ||
| setValueType(var1Tok, vt); | ||
| if (var1Tok != parent->previous()) | ||
| setValueType(parent->previous(), vt); | ||
|
|
@@ -7291,15 +7295,42 @@ | |
| } | ||
|
|
||
| // c++17 auto type deduction of braced init list | ||
| if (parent->isCpp() && mSettings.standards.cpp >= Standards::CPP17 && vt2 && Token::Match(parent->tokAt(-2), "auto %var% {")) { | ||
| Token *autoTok = parent->tokAt(-2); | ||
| setValueType(autoTok, *vt2); | ||
| setAutoTokenProperties(autoTok); | ||
| if (parent->previous()->variable()) | ||
| const_cast<Variable*>(parent->previous()->variable())->setValueType(*vt2); | ||
| else | ||
| debugMessage(parent->previous(), "debug", "Missing variable class for variable with varid"); | ||
| return; | ||
| if (parent->isCpp() && mSettings.standards.cpp >= Standards::CPP17 && vt2) { | ||
| Token *autoTok = nullptr; | ||
| if (Token::Match(parent->tokAt(-2), "auto %var% {")) | ||
Check warningCode scanning / Cppcheck Premium Use meaningful symbolic constants to represent literal values. Warning
Use meaningful symbolic constants to represent literal values.
|
||
| autoTok = parent->tokAt(-2); | ||
Check warningCode scanning / Cppcheck Premium Use meaningful symbolic constants to represent literal values. Warning
Use meaningful symbolic constants to represent literal values.
|
||
|
ludviggunne marked this conversation as resolved.
Dismissed
|
||
| else if (Token::Match(parent->tokAt(-3), "auto &|&&|* %var% {")) | ||
Check warningCode scanning / Cppcheck Premium Use meaningful symbolic constants to represent literal values. Warning
Use meaningful symbolic constants to represent literal values.
|
||
|
ludviggunne marked this conversation as resolved.
Dismissed
Collaborator
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. I feel that a loop that locates the auto would be better. I guess there can be const, multiple stars , etc.. |
||
| autoTok = parent->tokAt(-3); | ||
Check warningCode scanning / Cppcheck Premium Use meaningful symbolic constants to represent literal values. Warning
Use meaningful symbolic constants to represent literal values.
|
||
|
ludviggunne marked this conversation as resolved.
Dismissed
|
||
| if (autoTok) { | ||
| setValueType(autoTok, *vt2); | ||
| setAutoTokenProperties(autoTok); | ||
|
|
||
| Token *varTok = parent->astOperand1(); | ||
| auto *varVt = new ValueType(*vt2); | ||
| for (Token *qualTok = autoTok->next(); qualTok != varTok; qualTok = qualTok->next()) { | ||
| if (Token::simpleMatch(qualTok, "&")) { | ||
| varVt->reference = Reference::LValue; | ||
| continue; | ||
| } | ||
| if (Token::simpleMatch(qualTok, "&&")) { | ||
| varVt->reference = Reference::RValue; | ||
| continue; | ||
| } | ||
| if (Token::simpleMatch(qualTok, "*")) { | ||
| varVt->pointer++; | ||
| continue; | ||
| } | ||
| break; | ||
| } | ||
|
|
||
| varTok->setValueType(varVt); | ||
|
|
||
| if (parent->previous()->variable()) | ||
| const_cast<Variable*>(parent->previous()->variable())->setValueType(*varVt); | ||
| else | ||
| debugMessage(parent->previous(), "debug", "Missing variable class for variable with varid"); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| if (!vt1) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.