ValueType related bugfixes:
- ptrdiff_t is SIGNED - Detect pointers to unknown types as pointers - Do not identify bool* as boolean (#7381)
This commit is contained in:
parent
b4b38fb7ce
commit
0847d3d19a
|
@ -47,7 +47,7 @@ bool astIsFloat(const Token *tok, bool unknown)
|
|||
|
||||
bool astIsBool(const Token *tok)
|
||||
{
|
||||
return tok && (tok->isBoolean() || tok->valueType() && tok->valueType()->type == ValueType::Type::BOOL);
|
||||
return tok && (tok->isBoolean() || (tok->valueType() && tok->valueType()->type == ValueType::Type::BOOL && !tok->valueType()->pointer));
|
||||
}
|
||||
|
||||
std::string astCanonicalType(const Token *expr)
|
||||
|
|
|
@ -3751,7 +3751,7 @@ static void setValueType(Token *tok, const ValueType &valuetype, bool cpp, Value
|
|||
if (ternary || parent->tokType() == Token::eIncDecOp) // 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);
|
||||
setValueType(parent, ValueType(ValueType::Sign::SIGNED, ValueType::Type::INT, 0U, 0U, "ptrdiff_t"), cpp, defaultSignedness);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -3852,7 +3852,7 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
|
|||
valuetype->sign = ValueType::Sign::SIGNED;
|
||||
}
|
||||
|
||||
return (type && valuetype->type != ValueType::Type::UNKNOWN_TYPE) ? type : nullptr;
|
||||
return (type && (valuetype->type != ValueType::Type::UNKNOWN_TYPE || valuetype->pointer > 0)) ? type : nullptr;
|
||||
}
|
||||
|
||||
void SymbolDatabase::setValueTypeInTokenList(Token *tokens, bool cpp, char defaultSignedness)
|
||||
|
|
|
@ -84,7 +84,6 @@ private:
|
|||
|
||||
|
||||
void assignBoolToPointer() {
|
||||
|
||||
check("void foo(bool *p) {\n"
|
||||
" p = false;\n"
|
||||
"}");
|
||||
|
@ -164,6 +163,13 @@ private:
|
|||
" : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\n"
|
||||
"}", /*experimental=*/false, "test.c");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #7381
|
||||
check("void foo(bool *p, bool b) {\n"
|
||||
" p = b;\n"
|
||||
" p = &b;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Boolean value assigned to pointer.\n", errout.str());
|
||||
}
|
||||
|
||||
void assignBoolToFloat() {
|
||||
|
|
|
@ -3254,6 +3254,9 @@ private:
|
|||
|
||||
// Static members
|
||||
ASSERT_EQUALS("signed int", typeOf("struct AB { static int a; }; x = AB::a;", "::"));
|
||||
|
||||
// Pointer to unknown type
|
||||
ASSERT_EQUALS("*", typeOf("Bar* b;", "b"));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue