ValueType: Properly support ternary operator with pointers (#7378)

This commit is contained in:
PKEuS 2016-02-05 09:59:27 +01:00
parent b45c2851b0
commit 2b179dc836
2 changed files with 7 additions and 2 deletions

View File

@ -3749,8 +3749,11 @@ static void setValueType(Token *tok, const ValueType &valuetype, bool cpp, Value
return;
}
if (vt1->pointer != 0U) { // result is pointer diff
setValueType(parent, ValueType(ValueType::Sign::UNSIGNED, ValueType::Type::INT, 0U, 0U, "ptrdiff_t"), cpp, defaultSignedness);
if (vt1->pointer != 0U) {
if (ternary) // result is pointer
setValueType(parent, *vt1, cpp, defaultSignedness);
else // result is pointer diff
setValueType(parent, ValueType(ValueType::Sign::UNSIGNED, ValueType::Type::INT, 0U, 0U, "ptrdiff_t"), cpp, defaultSignedness);
return;
}

View File

@ -3199,6 +3199,8 @@ private:
ASSERT_EQUALS("signed int", typeOf("int x; a = (b ? x : x)", "?"));
ASSERT_EQUALS("", typeOf("int x; a = (b ? x : y)", "?"));
ASSERT_EQUALS("double", typeOf("int x; double y; a = (b ? x : y)", "?"));
ASSERT_EQUALS("const char *", typeOf("int x; double y; a = (b ? \"a\" : \"b\")", "?"));
ASSERT_EQUALS("", typeOf("int x; double y; a = (b ? \"a\" : std::string(\"b\"))", "?"));
// shift => result has same type as lhs
ASSERT_EQUALS("signed int", typeOf("int x; a = x << 1U;", "<<"));