Fixed #8964 (ValueType: auto constness)

This commit is contained in:
Daniel Marjamäki 2019-02-24 08:16:08 +01:00
parent 32e1d383a4
commit ef731064bd
2 changed files with 22 additions and 1 deletions

View File

@ -4919,7 +4919,12 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
setValueType(parent->previous(), *vt2); setValueType(parent->previous(), *vt2);
Variable *var = const_cast<Variable *>(parent->previous()->variable()); Variable *var = const_cast<Variable *>(parent->previous()->variable());
if (var) { 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) { if (vt2->typeScope && vt2->typeScope->definedType) {
var->type(vt2->typeScope->definedType); var->type(vt2->typeScope->definedType);
if (autoTok->valueType()->pointer == 0) if (autoTok->valueType()->pointer == 0)

View File

@ -380,6 +380,7 @@ private:
TEST_CASE(auto8); TEST_CASE(auto8);
TEST_CASE(auto9); // #8044 (segmentation fault) TEST_CASE(auto9); // #8044 (segmentation fault)
TEST_CASE(auto10); // #8020 TEST_CASE(auto10); // #8020
TEST_CASE(auto11); // #8964 - const auto startX = x;
TEST_CASE(unionWithConstructor); 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() { void unionWithConstructor() {
GET_SYMBOL_DB("union Fred {\n" GET_SYMBOL_DB("union Fred {\n"
" Fred(int x) : i(x) { }\n" " Fred(int x) : i(x) { }\n"