From ef731064bd678d78dfa0feadf9bedadc3e39d86f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 24 Feb 2019 08:16:08 +0100 Subject: [PATCH] Fixed #8964 (ValueType: auto constness) --- lib/symboldatabase.cpp | 7 ++++++- test/testsymboldatabase.cpp | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 73e645ed9..72909986a 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4919,7 +4919,12 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype) setValueType(parent->previous(), *vt2); Variable *var = const_cast(parent->previous()->variable()); if (var) { - var->setValueType(*vt2); + ValueType vt2_(*vt2); + if (vt2_.pointer == 0 && autoTok->strAt(1) == "*") + vt2_.pointer = 1; + if ((vt.constness & (1 << vt2->pointer)) != 0) + vt2_.constness |= (1 << vt2->pointer); + var->setValueType(vt2_); if (vt2->typeScope && vt2->typeScope->definedType) { var->type(vt2->typeScope->definedType); if (autoTok->valueType()->pointer == 0) diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 93b2f1b73..a560b33b2 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -380,6 +380,7 @@ private: TEST_CASE(auto8); TEST_CASE(auto9); // #8044 (segmentation fault) TEST_CASE(auto10); // #8020 + TEST_CASE(auto11); // #8964 - const auto startX = x; TEST_CASE(unionWithConstructor); } @@ -6817,6 +6818,21 @@ private: } } + void auto11() { + GET_SYMBOL_DB("void f() {\n" + " const auto v1 = 3;\n" + " const auto *v2 = 0;\n" + "}"); + + (void)db; + + const Token *v1tok = Token::findsimplematch(tokenizer.tokens(), "v1"); + ASSERT(v1tok && v1tok->variable() && v1tok->variable()->isConst()); + + const Token *v2tok = Token::findsimplematch(tokenizer.tokens(), "v2"); + ASSERT(v2tok && v2tok->variable() && !v2tok->variable()->isConst()); + } + void unionWithConstructor() { GET_SYMBOL_DB("union Fred {\n" " Fred(int x) : i(x) { }\n"