diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 17f1f94b8..ad5135258 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4837,6 +4837,9 @@ void SymbolDatabase::setValueType(Token *tok, const Variable &var) valuetype.bits = var.nameToken()->bits(); valuetype.pointer = var.dimensions().size(); valuetype.typeScope = var.typeScope(); + if (var.valueType()) { + valuetype.container = var.valueType()->container; + } if (parsedecl(var.typeStartToken(), &valuetype, mDefaultSignedness, mSettings)) { if (tok->str() == "." && tok->astOperand1()) { const ValueType * const vt = tok->astOperand1()->valueType(); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 4410c82d6..aeefbb9e5 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -381,6 +381,7 @@ private: TEST_CASE(auto9); // #8044 (segmentation fault) TEST_CASE(auto10); // #8020 TEST_CASE(auto11); // #8964 - const auto startX = x; + TEST_CASE(auto12); // #8993 - const std::string &x; auto y = x; if (y.empty()) .. TEST_CASE(unionWithConstructor); } @@ -6833,6 +6834,22 @@ private: ASSERT(v2tok && v2tok->variable() && !v2tok->variable()->isConst()); } + void auto12() { + GET_SYMBOL_DB("void f(const std::string &x) {\n" + " auto y = x;\n" + " if (y.empty()) {}\n" + "}"); + (void)db; + + const Token *tok; + + tok = Token::findsimplematch(tokenizer.tokens(), "y ="); + ASSERT(tok && tok->valueType() && tok->valueType()->container); + + tok = Token::findsimplematch(tokenizer.tokens(), "y ."); + ASSERT(tok && tok->valueType() && tok->valueType()->container); + } + void unionWithConstructor() { GET_SYMBOL_DB("union Fred {\n" " Fred(int x) : i(x) { }\n"