From 2da3123db2401574de729f0dd0ba47a0a1dbcc35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 30 Mar 2017 11:01:29 +0200 Subject: [PATCH] Fix ValueType. The '[' in variable declaration is not a dereference. --- lib/symboldatabase.cpp | 8 +++++++- test/testsymboldatabase.cpp | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index bffaeb6ef..042cad03e 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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; } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index cd4d50297..935aee9a2 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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