Skip to content

Commit 4e48737

Browse files
committed
Fixed #7395 (ValueType: Result type of assignment operators)
1 parent 19c0bcc commit 4e48737

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3688,6 +3688,12 @@ static void setValueType(Token *tok, const ValueType &valuetype, bool cpp, Value
36883688
return;
36893689
}
36903690

3691+
if (parent->isAssignmentOp()) {
3692+
if (vt1)
3693+
setValueType(parent, *vt1, cpp, defaultSignedness);
3694+
return;
3695+
}
3696+
36913697
if (parent->str() == "[" && valuetype.pointer > 0U) {
36923698
ValueType vt(valuetype);
36933699
vt.pointer -= 1U;

test/testsymboldatabase.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3220,6 +3220,9 @@ class TestSymbolDatabase: public TestFixture {
32203220
ASSERT_EQUALS("", typeOf("a = 12 << x;", "<<", "test.cpp")); // << might be overloaded
32213221
ASSERT_EQUALS("signed int", typeOf("a = 12 << x;", "<<", "test.c"));
32223222

3223+
// assignment => result has same type as lhs
3224+
ASSERT_EQUALS("unsigned short", typeOf("unsigned short x; x = 3;", "="));
3225+
32233226
// array..
32243227
ASSERT_EQUALS("void * *", typeOf("void * x[10]; a = x + 0;", "+"));
32253228
ASSERT_EQUALS("signed int *", typeOf("int x[10]; a = x + 1;", "+"));

0 commit comments

Comments
 (0)