ValueType: Properly support ternary operator with pointers (#7378)
This commit is contained in:
parent
b45c2851b0
commit
2b179dc836
|
@ -3749,7 +3749,10 @@ static void setValueType(Token *tok, const ValueType &valuetype, bool cpp, Value
|
|||
return;
|
||||
}
|
||||
|
||||
if (vt1->pointer != 0U) { // result is pointer diff
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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;", "<<"));
|
||||
|
|
Loading…
Reference in New Issue