@@ -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,55 @@ 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
7299+ && Token::Match (parent->astOperand1 (), " %var% {" ) && vt2) {
7300+
7301+ auto reference = Reference::None;
7302+ nonneg int pointer = 0 ;
7303+ nonneg int constness = 0 ;
7304+ nonneg int volatileness = 0 ;
7305+
7306+ Token *varTok = parent->astOperand1 ();
7307+ Token *typeTok = varTok->previous ();
7308+
7309+ while (Token::Match (typeTok, " &|&&|*|const|volatile" )) {
7310+ if (typeTok->str () == " &" )
7311+ reference = Reference::LValue;
7312+ else if (typeTok->str () == " &&" )
7313+ reference = Reference::RValue;
7314+ else if (typeTok->str () == " *" )
7315+ pointer++;
7316+ else if (typeTok->str () == " const" )
7317+ constness |= 1 << pointer;
7318+ else if (typeTok->str () == " volatile" )
7319+ volatileness |= 1 << pointer;
7320+ typeTok = typeTok->previous ();
7321+ }
7322+
7323+ if (typeTok->str () == " auto" ) {
7324+ setValueType (typeTok, *vt2);
7325+ setAutoTokenProperties (typeTok);
7326+
7327+ auto *varVt = new ValueType (*vt2);
7328+
7329+ varVt->reference = reference;
7330+ varVt->constness |= constness;
7331+ varVt->volatileness |= volatileness;
7332+
7333+ if (Token::simpleMatch (typeTok->previous (), " const auto" ))
7334+ varVt->constness |= 1 << pointer;
7335+
7336+ if (Token::simpleMatch (typeTok->previous (), " volatile auto" ))
7337+ varVt->volatileness |= 1 << pointer;
7338+
7339+ varTok->setValueType (varVt);
7340+
7341+ if (varTok->variable ())
7342+ const_cast <Variable*>(varTok->variable ())->setValueType (*varVt);
7343+ else
7344+ debugMessage (varTok, " debug" , " Missing variable class for variable with varid" );
7345+ return ;
7346+ }
73037347 }
73047348
73057349 if (!vt1)
0 commit comments