From 397480f929bab4f1f6f4afdef649a202bb07e994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 23 May 2016 18:53:59 +0200 Subject: [PATCH] Fixed #7376 (ValueType: wrong type for container element) --- lib/symboldatabase.cpp | 2 +- test/testsymboldatabase.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) 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;", "("));