diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index ff1bd88c38f..0e0f90e603b 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -6789,11 +6789,15 @@ static const Token* parsedecl(const Token* type, valuetype->constness = vt->constness; valuetype->originalTypeName = vt->originalTypeName; const bool hasConst = Token::simpleMatch(type->previous(), "const"); - while (Token::Match(type, "%name%|*|&|::") && !type->variable()) { + while (Token::Match(type, "%name%|*|&|&&|::") && !type->variable()) { if (type->str() == "*") { valuetype->pointer = 1; if (hasConst) valuetype->constness = 1; + } else if (type->str() == "&") { + valuetype->reference = Reference::LValue; + } else if (type->str() == "&&") { + valuetype->reference = Reference::RValue; } if (type->str() == "const") valuetype->constness |= (1 << valuetype->pointer); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 62f0e4a6963..13c7846061f 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -512,6 +512,7 @@ class TestSymbolDatabase : public TestFixture { TEST_CASE(auto19); TEST_CASE(auto20); TEST_CASE(auto21); + TEST_CASE(auto22); TEST_CASE(unionWithConstructor); @@ -8412,7 +8413,7 @@ class TestSymbolDatabase : public TestFixture { const Token* tok = tokenizer.tokens(); tok = Token::findsimplematch(tok, "s ."); ASSERT(tok && tok->valueType()); - ASSERT_EQUALS("container(std :: set|unordered_set <)", tok->valueType()->str()); + ASSERT_EQUALS("container(std :: set|unordered_set <) &", tok->valueType()->str()); } { GET_SYMBOL_DB("void f(std::vector v) {\n" @@ -9487,6 +9488,22 @@ class TestSymbolDatabase : public TestFixture { ASSERT(v->variable() && v->variable()->isReference()); } + void auto22() { + GET_SYMBOL_DB("void f(std::vector& v, bool b) {\n" + " auto& s = b ? v[0] : v[1];\n" + " s += \"abc\";\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + const Token* a = Token::findsimplematch(tokenizer.tokens(), "auto"); + ASSERT(a && a->valueType()); + ASSERT_EQUALS(a->valueType()->type, ValueType::CONTAINER); + const Token* s = Token::findsimplematch(a, "s +="); + ASSERT(s && s->valueType()); + ASSERT_EQUALS(s->valueType()->type, ValueType::CONTAINER); + ASSERT(s->valueType()->reference == Reference::LValue); + ASSERT(s->variable() && s->variable()->isReference()); + } + void unionWithConstructor() { GET_SYMBOL_DB("union Fred {\n" " Fred(int x) : i(x) { }\n"