make result of <<|>> an xvalue (#2775)

This commit is contained in:
shaneasd 2020-09-05 18:07:06 +08:00 committed by GitHub
parent 7d51baa2f0
commit 9712c136bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -5355,12 +5355,15 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
if (vt1 && Token::Match(parent, "<<|>>")) { if (vt1 && Token::Match(parent, "<<|>>")) {
if (!mIsCpp || (vt2 && vt2->isIntegral())) { if (!mIsCpp || (vt2 && vt2->isIntegral())) {
if (vt1->type < ValueType::Type::BOOL || vt1->type >= ValueType::Type::INT) if (vt1->type < ValueType::Type::BOOL || vt1->type >= ValueType::Type::INT) {
setValueType(parent, *vt1); ValueType vt(*vt1);
else { vt.reference = Reference::None;
setValueType(parent, vt);
} else {
ValueType vt(*vt1); ValueType vt(*vt1);
vt.type = ValueType::Type::INT; // Integer promotion vt.type = ValueType::Type::INT; // Integer promotion
vt.sign = ValueType::Sign::SIGNED; vt.sign = ValueType::Sign::SIGNED;
vt.reference = Reference::None;
setValueType(parent, vt); setValueType(parent, vt);
} }

View File

@ -6814,6 +6814,7 @@ private:
ASSERT_EQUALS("A::BC *", typeOf("namespace A { struct BC { int b; int c; }; }; struct A::BC abc; x=&abc;", "&")); ASSERT_EQUALS("A::BC *", typeOf("namespace A { struct BC { int b; int c; }; }; struct A::BC abc; x=&abc;", "&"));
ASSERT_EQUALS("A::BC *", typeOf("namespace A { struct BC { int b; int c; }; }; struct A::BC *abc; x=abc+1;", "+")); ASSERT_EQUALS("A::BC *", typeOf("namespace A { struct BC { int b; int c; }; }; struct A::BC *abc; x=abc+1;", "+"));
ASSERT_EQUALS("signed int", typeOf("auto a(int& x, int& y) { return x + y; }", "+")); ASSERT_EQUALS("signed int", typeOf("auto a(int& x, int& y) { return x + y; }", "+"));
ASSERT_EQUALS("signed int", typeOf("auto a(int& x) { return x << 1; }", "<<"));
ASSERT_EQUALS("signed int", typeOf("void a(int& x, int& y) { x = y; }", "=")); //Debatably this should be a signed int & but we'll stick with the current behavior for now ASSERT_EQUALS("signed int", typeOf("void a(int& x, int& y) { x = y; }", "=")); //Debatably this should be a signed int & but we'll stick with the current behavior for now
ASSERT_EQUALS("signed int", typeOf("auto a(int* y) { return *y; }", "*")); //Debatably this should be a signed int & but we'll stick with the current behavior for now ASSERT_EQUALS("signed int", typeOf("auto a(int* y) { return *y; }", "*")); //Debatably this should be a signed int & but we'll stick with the current behavior for now