diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a10c737f7..ceb06e07d 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4149,7 +4149,7 @@ static void setValueType(Token *tok, const ValueType &valuetype, bool cpp, Value return; } - if (parent->str() == "[" && valuetype.pointer > 0U) { + if (parent->str() == "[" && (!cpp || parent->astOperand1() == tok) && valuetype.pointer > 0U) { ValueType vt(valuetype); vt.pointer -= 1U; setValueType(parent, vt, cpp, defaultSignedness, lib); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index d23532b9f..fd55e6049 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -3330,6 +3330,8 @@ private: ASSERT_EQUALS("void * *", typeOf("void * x[10]; a = x + 0;", "+")); ASSERT_EQUALS("signed int *", typeOf("int x[10]; a = x + 1;", "+")); ASSERT_EQUALS("signed int", typeOf("int x[10]; a = x[0] + 1;", "+")); + ASSERT_EQUALS("", typeOf("a = x[\"hello\"];", "[", "test.cpp")); + ASSERT_EQUALS("const char", typeOf("a = x[\"hello\"];", "[", "test.c")); // cast.. ASSERT_EQUALS("void *", typeOf("a = (void *)0;", "("));