Fix ValueType. The '[' in variable declaration is not a dereference.

This commit is contained in:
Daniel Marjamäki 2017-03-30 11:01:29 +02:00
parent cc3ef7bbe8
commit 2da3123db2
2 changed files with 10 additions and 1 deletions

View File

@ -4579,8 +4579,14 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
}
if (parent->str() == "[" && (!cpp || parent->astOperand1() == tok) && valuetype.pointer > 0U) {
const Token *op1 = parent->astOperand1();
while (op1 && op1->str() == "[")
op1 = op1->astOperand1();
ValueType vt(valuetype);
vt.pointer -= 1U;
// the "[" is a dereference unless this is a variable declaration
if (!(op1 && op1->variable() && op1->variable()->nameToken() == op1))
vt.pointer -= 1U;
setValueType(parent, vt);
return;
}

View File

@ -4426,6 +4426,9 @@ private:
ASSERT_EQUALS("signed int *", typeOf("; auto data = new (std::nothrow) int[100];", "data"));
ASSERT_EQUALS("const signed short", typeOf("short values[10]; void f() { for (const auto *x : values); }", "x"));
ASSERT_EQUALS("signed int *", typeOf("MACRO(test) void test() { auto x = (int*)y; }", "x")); // #7931 (garbage?)
// Variable declaration
ASSERT_EQUALS("char *", typeOf("; char abc[] = \"abc\";", "["));
}
void variadic1() { // #7453