Fixed #7376 (ValueType: wrong type for container element)

This commit is contained in:
Daniel Marjamäki 2016-05-23 18:53:59 +02:00
parent 37afc57a2a
commit 397480f929
2 changed files with 3 additions and 1 deletions

View File

@ -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);

View File

@ -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;", "("));