diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 18221cef5..c7b67cdee 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -6207,7 +6207,19 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source if (parent->str() == "&" && !parent->astOperand2()) { ValueType vt(valuetype); vt.reference = Reference::None; //Given int& x; the type of &x is int* not int&* - vt.pointer += 1U; + bool isArrayToPointerDecay = false; + for (const Token* child = parent->astOperand1(); child;) { + if (Token::Match(child, ".|::")) + child = child->astOperand2(); + else if (Token::simpleMatch(child, "[")) + child = child->astOperand1(); + else { + isArrayToPointerDecay = child->variable() && child->variable()->isArray(); + break; + } + } + if (!isArrayToPointerDecay) + vt.pointer += 1U; setValueType(parent, vt); return; } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 8d08888a2..d7ebfd425 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -7601,6 +7601,7 @@ private: 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")); + ASSERT_EQUALS("signed int *", typeOf("int x[10]; a = &x;", "&")); // cast.. ASSERT_EQUALS("void *", typeOf("a = (void *)0;", "("));