Fix ValueType. The '[' in variable declaration is not a dereference.
This commit is contained in:
parent
cc3ef7bbe8
commit
2da3123db2
|
@ -4579,8 +4579,14 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent->str() == "[" && (!cpp || parent->astOperand1() == tok) && valuetype.pointer > 0U) {
|
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);
|
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);
|
setValueType(parent, vt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4426,6 +4426,9 @@ private:
|
||||||
ASSERT_EQUALS("signed int *", typeOf("; auto data = new (std::nothrow) int[100];", "data"));
|
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("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?)
|
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
|
void variadic1() { // #7453
|
||||||
|
|
Loading…
Reference in New Issue