Skip to content

Commit

Permalink
Fixed #7395 (ValueType: Result type of assignment operators)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Mar 21, 2016
1 parent 19c0bcc commit 4e48737
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3688,6 +3688,12 @@ static void setValueType(Token *tok, const ValueType &valuetype, bool cpp, Value
return;
}

if (parent->isAssignmentOp()) {
if (vt1)
setValueType(parent, *vt1, cpp, defaultSignedness);
return;
}

if (parent->str() == "[" && valuetype.pointer > 0U) {
ValueType vt(valuetype);
vt.pointer -= 1U;
Expand Down
3 changes: 3 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3220,6 +3220,9 @@ class TestSymbolDatabase: public TestFixture {
ASSERT_EQUALS("", typeOf("a = 12 << x;", "<<", "test.cpp")); // << might be overloaded
ASSERT_EQUALS("signed int", typeOf("a = 12 << x;", "<<", "test.c"));

// assignment => result has same type as lhs
ASSERT_EQUALS("unsigned short", typeOf("unsigned short x; x = 3;", "="));

// array..
ASSERT_EQUALS("void * *", typeOf("void * x[10]; a = x + 0;", "+"));
ASSERT_EQUALS("signed int *", typeOf("int x[10]; a = x + 1;", "+"));
Expand Down

0 comments on commit 4e48737

Please sign in to comment.