Skip to content

Commit 2da3123

Browse files
committed
Fix ValueType. The '[' in variable declaration is not a dereference.
1 parent cc3ef7b commit 2da3123

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/symboldatabase.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4579,8 +4579,14 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
45794579
}
45804580

45814581
if (parent->str() == "[" && (!cpp || parent->astOperand1() == tok) && valuetype.pointer > 0U) {
4582+
const Token *op1 = parent->astOperand1();
4583+
while (op1 && op1->str() == "[")
4584+
op1 = op1->astOperand1();
4585+
45824586
ValueType vt(valuetype);
4583-
vt.pointer -= 1U;
4587+
// the "[" is a dereference unless this is a variable declaration
4588+
if (!(op1 && op1->variable() && op1->variable()->nameToken() == op1))
4589+
vt.pointer -= 1U;
45844590
setValueType(parent, vt);
45854591
return;
45864592
}

test/testsymboldatabase.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4426,6 +4426,9 @@ class TestSymbolDatabase: public TestFixture {
44264426
ASSERT_EQUALS("signed int *", typeOf("; auto data = new (std::nothrow) int[100];", "data"));
44274427
ASSERT_EQUALS("const signed short", typeOf("short values[10]; void f() { for (const auto *x : values); }", "x"));
44284428
ASSERT_EQUALS("signed int *", typeOf("MACRO(test) void test() { auto x = (int*)y; }", "x")); // #7931 (garbage?)
4429+
4430+
// Variable declaration
4431+
ASSERT_EQUALS("char *", typeOf("; char abc[] = \"abc\";", "["));
44294432
}
44304433

44314434
void variadic1() { // #7453

0 commit comments

Comments
 (0)