Skip to content

Commit 9e49b8b

Browse files
committed
fix
1 parent 8db25ed commit 9e49b8b

1 file changed

Lines changed: 40 additions & 9 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7017,6 +7017,10 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
70177017
setAutoTokenProperties(autoTok);
70187018
if (vt2->pointer > vt.pointer)
70197019
vt.pointer++;
7020+
if (Token::simpleMatch(autoTok->next(), "&"))
7021+
vt.reference = Reference::LValue;
7022+
if (Token::simpleMatch(autoTok->next(), "&&"))
7023+
vt.reference = Reference::RValue;
70207024
setValueType(var1Tok, vt);
70217025
if (var1Tok != parent->previous())
70227026
setValueType(parent->previous(), vt);
@@ -7291,15 +7295,42 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
72917295
}
72927296

72937297
// c++17 auto type deduction of braced init list
7294-
if (parent->isCpp() && mSettings.standards.cpp >= Standards::CPP17 && vt2 && Token::Match(parent->tokAt(-2), "auto %var% {")) {
7295-
Token *autoTok = parent->tokAt(-2);
7296-
setValueType(autoTok, *vt2);
7297-
setAutoTokenProperties(autoTok);
7298-
if (parent->previous()->variable())
7299-
const_cast<Variable*>(parent->previous()->variable())->setValueType(*vt2);
7300-
else
7301-
debugMessage(parent->previous(), "debug", "Missing variable class for variable with varid");
7302-
return;
7298+
if (parent->isCpp() && mSettings.standards.cpp >= Standards::CPP17 && vt2) {
7299+
Token *autoTok = nullptr;
7300+
if (Token::Match(parent->tokAt(-2), "auto %var% {"))
7301+
autoTok = parent->tokAt(-2);
7302+
else if (Token::Match(parent->tokAt(-3), "auto &|&&|* %var% {"))
7303+
autoTok = parent->tokAt(-3);
7304+
if (autoTok) {
7305+
setValueType(autoTok, *vt2);
7306+
setAutoTokenProperties(autoTok);
7307+
7308+
Token *varTok = parent->astOperand1();
7309+
ValueType *varVt = new ValueType(*vt2);
7310+
for (Token *qualTok = autoTok->next(); qualTok != varTok; qualTok = qualTok->next()) {
7311+
if (Token::simpleMatch(qualTok, "&")) {
7312+
varVt->reference = Reference::LValue;
7313+
continue;
7314+
}
7315+
if (Token::simpleMatch(qualTok, "&&")) {
7316+
varVt->reference = Reference::RValue;
7317+
continue;
7318+
}
7319+
if (Token::simpleMatch(qualTok, "*")) {
7320+
varVt->pointer++;
7321+
continue;
7322+
}
7323+
break;
7324+
}
7325+
7326+
varTok->setValueType(varVt);
7327+
7328+
if (parent->previous()->variable())
7329+
const_cast<Variable*>(parent->previous()->variable())->setValueType(*varVt);
7330+
else
7331+
debugMessage(parent->previous(), "debug", "Missing variable class for variable with varid");
7332+
return;
7333+
}
73037334
}
73047335

73057336
if (!vt1)

0 commit comments

Comments
 (0)