@@ -7021,6 +7021,10 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
70217021 setAutoTokenProperties (autoTok);
70227022 if (vt2->pointer > vt.pointer )
70237023 vt.pointer ++;
7024+ if (Token::simpleMatch (autoTok->next (), " &" ))
7025+ vt.reference = Reference::LValue;
7026+ if (Token::simpleMatch (autoTok->next (), " &&" ))
7027+ vt.reference = Reference::RValue;
70247028 setValueType (var1Tok, vt);
70257029 if (var1Tok != parent->previous ())
70267030 setValueType (parent->previous (), vt);
@@ -7295,15 +7299,55 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
72957299 }
72967300
72977301 // c++17 auto type deduction of braced init list
7298- if (parent->isCpp () && mSettings .standards .cpp >= Standards::CPP17 && vt2 && Token::Match (parent->tokAt (-2 ), " auto %var% {" )) {
7299- Token *autoTok = parent->tokAt (-2 );
7300- setValueType (autoTok, *vt2);
7301- setAutoTokenProperties (autoTok);
7302- if (parent->previous ()->variable ())
7303- const_cast <Variable*>(parent->previous ()->variable ())->setValueType (*vt2);
7304- else
7305- debugMessage (parent->previous (), " debug" , " Missing variable class for variable with varid" );
7306- return ;
7302+ if (parent->isCpp () && mSettings .standards .cpp >= Standards::CPP17
7303+ && Token::Match (parent->astOperand1 (), " %var% {" ) && vt2) {
7304+
7305+ auto reference = Reference::None;
7306+ nonneg int pointer = 0 ;
7307+ nonneg int constness = 0 ;
7308+ nonneg int volatileness = 0 ;
7309+
7310+ Token *varTok = parent->astOperand1 ();
7311+ Token *typeTok = varTok->previous ();
7312+
7313+ while (Token::Match (typeTok, " &|&&|*|const|volatile" )) {
7314+ if (typeTok->str () == " &" )
7315+ reference = Reference::LValue;
7316+ else if (typeTok->str () == " &&" )
7317+ reference = Reference::RValue;
7318+ else if (typeTok->str () == " *" )
7319+ pointer++;
7320+ else if (typeTok->str () == " const" )
7321+ constness |= 1 << pointer;
7322+ else if (typeTok->str () == " volatile" )
7323+ volatileness |= 1 << pointer;
7324+ typeTok = typeTok->previous ();
7325+ }
7326+
7327+ if (typeTok->str () == " auto" ) {
7328+ setValueType (typeTok, *vt2);
7329+ setAutoTokenProperties (typeTok);
7330+
7331+ auto *varVt = new ValueType (*vt2);
7332+
7333+ varVt->reference = reference;
7334+ varVt->constness |= constness;
7335+ varVt->volatileness |= volatileness;
7336+
7337+ if (Token::simpleMatch (typeTok->previous (), " const auto" ))
7338+ varVt->constness |= 1 << pointer;
7339+
7340+ if (Token::simpleMatch (typeTok->previous (), " volatile auto" ))
7341+ varVt->volatileness |= 1 << pointer;
7342+
7343+ varTok->setValueType (varVt);
7344+
7345+ if (varTok->variable ())
7346+ const_cast <Variable*>(varTok->variable ())->setValueType (*varVt);
7347+ else
7348+ debugMessage (varTok, " debug" , " Missing variable class for variable with varid" );
7349+ return ;
7350+ }
73077351 }
73087352
73097353 if (!vt1)
0 commit comments