@@ -7015,6 +7015,10 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
70157015 setAutoTokenProperties (autoTok);
70167016 if (vt2->pointer > vt.pointer )
70177017 vt.pointer ++;
7018+ if (Token::simpleMatch (autoTok->next (), " &" ))
7019+ vt.reference = Reference::LValue;
7020+ if (Token::simpleMatch (autoTok->next (), " &&" ))
7021+ vt.reference = Reference::RValue;
70187022 setValueType (var1Tok, vt);
70197023 if (var1Tok != parent->previous ())
70207024 setValueType (parent->previous (), vt);
@@ -7289,15 +7293,55 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
72897293 }
72907294
72917295 // c++17 auto type deduction of braced init list
7292- if (parent->isCpp () && mSettings .standards .cpp >= Standards::CPP17 && vt2 && Token::Match (parent->tokAt (-2 ), " auto %var% {" )) {
7293- Token *autoTok = parent->tokAt (-2 );
7294- setValueType (autoTok, *vt2);
7295- setAutoTokenProperties (autoTok);
7296- if (parent->previous ()->variable ())
7297- const_cast <Variable*>(parent->previous ()->variable ())->setValueType (*vt2);
7298- else
7299- debugMessage (parent->previous (), " debug" , " Missing variable class for variable with varid" );
7300- return ;
7296+ if (parent->isCpp () && mSettings .standards .cpp >= Standards::CPP17
7297+ && Token::Match (parent->astOperand1 (), " %var% {" ) && vt2) {
7298+
7299+ auto reference = Reference::None;
7300+ nonneg int pointer = 0 ;
7301+ nonneg int constness = 0 ;
7302+ nonneg int volatileness = 0 ;
7303+
7304+ Token *varTok = parent->astOperand1 ();
7305+ Token *typeTok = varTok->previous ();
7306+
7307+ while (Token::Match (typeTok, " &|&&|*|const|volatile" )) {
7308+ if (typeTok->str () == " &" )
7309+ reference = Reference::LValue;
7310+ else if (typeTok->str () == " &&" )
7311+ reference = Reference::RValue;
7312+ else if (typeTok->str () == " *" )
7313+ pointer++;
7314+ else if (typeTok->str () == " const" )
7315+ constness |= 1 << pointer;
7316+ else if (typeTok->str () == " volatile" )
7317+ volatileness |= 1 << pointer;
7318+ typeTok = typeTok->previous ();
7319+ }
7320+
7321+ if (typeTok->str () == " auto" ) {
7322+ setValueType (typeTok, *vt2);
7323+ setAutoTokenProperties (typeTok);
7324+
7325+ auto *varVt = new ValueType (*vt2);
7326+
7327+ varVt->reference = reference;
7328+ varVt->constness |= constness;
7329+ varVt->volatileness |= volatileness;
7330+
7331+ if (Token::simpleMatch (typeTok->previous (), " const auto" ))
7332+ varVt->constness |= 1 << pointer;
7333+
7334+ if (Token::simpleMatch (typeTok->previous (), " volatile auto" ))
7335+ varVt->volatileness |= 1 << pointer;
7336+
7337+ varTok->setValueType (varVt);
7338+
7339+ if (varTok->variable ())
7340+ const_cast <Variable*>(varTok->variable ())->setValueType (*varVt);
7341+ else
7342+ debugMessage (varTok, " debug" , " Missing variable class for variable with varid" );
7343+ return ;
7344+ }
73017345 }
73027346
73037347 if (!vt1)
0 commit comments