Fixed ValueType for auto variable

This commit is contained in:
Daniel Marjamäki 2019-02-27 10:28:18 +01:00
parent 032020c40d
commit 226f0c7544
2 changed files with 20 additions and 0 deletions

View File

@ -4837,6 +4837,9 @@ void SymbolDatabase::setValueType(Token *tok, const Variable &var)
valuetype.bits = var.nameToken()->bits(); valuetype.bits = var.nameToken()->bits();
valuetype.pointer = var.dimensions().size(); valuetype.pointer = var.dimensions().size();
valuetype.typeScope = var.typeScope(); valuetype.typeScope = var.typeScope();
if (var.valueType()) {
valuetype.container = var.valueType()->container;
}
if (parsedecl(var.typeStartToken(), &valuetype, mDefaultSignedness, mSettings)) { if (parsedecl(var.typeStartToken(), &valuetype, mDefaultSignedness, mSettings)) {
if (tok->str() == "." && tok->astOperand1()) { if (tok->str() == "." && tok->astOperand1()) {
const ValueType * const vt = tok->astOperand1()->valueType(); const ValueType * const vt = tok->astOperand1()->valueType();

View File

@ -381,6 +381,7 @@ private:
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(auto11); // #8964 - const auto startX = x;
TEST_CASE(auto12); // #8993 - const std::string &x; auto y = x; if (y.empty()) ..
TEST_CASE(unionWithConstructor); TEST_CASE(unionWithConstructor);
} }
@ -6833,6 +6834,22 @@ private:
ASSERT(v2tok && v2tok->variable() && !v2tok->variable()->isConst()); 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() { 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"