Fixed #7713 (False positive: %hhu in format string (no. 1) requires 'unsigned char' but the argument type is 'signed int'.)

This commit is contained in:
Robert Reif 2016-08-26 19:47:36 +02:00 committed by Daniel Marjamäki
parent 87409ea6b3
commit bf7ef56ef5
2 changed files with 36 additions and 3 deletions

View File

@ -4406,9 +4406,29 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
valuetype->sign = ValueType::Sign::UNKNOWN_SIGN;
if (!valuetype->typeScope)
valuetype->type = ValueType::Type::UNKNOWN_TYPE;
else if (valuetype->typeScope->type == Scope::eEnum)
valuetype->type = ValueType::Type::INT;
else
else if (valuetype->typeScope->type == Scope::eEnum) {
const Token * enum_type = valuetype->typeScope->enumType;
if (enum_type) {
if (enum_type->isSigned())
valuetype->sign = ValueType::Sign::SIGNED;
else if (enum_type->isUnsigned())
valuetype->sign = ValueType::Sign::UNSIGNED;
else
valuetype->sign = defaultSignedness;
if (enum_type->str() == "char")
valuetype->type = ValueType::Type::CHAR;
else if (enum_type->str() == "short")
valuetype->type = ValueType::Type::SHORT;
else if (enum_type->str() == "int")
valuetype->type = ValueType::Type::INT;
else if (enum_type->str() == "long")
valuetype->type = enum_type->isLong() ? ValueType::Type::LONGLONG : ValueType::Type::LONG;
else if (enum_type->isStandardType()) {
valuetype->fromLibraryType(enum_type->str(), settings);
}
} else
valuetype->type = ValueType::Type::INT;
} else
valuetype->type = ValueType::Type::NONSTD;
while (Token::Match(type, "%name%|*|&|::") && !type->variable()) {
if (type->isSigned())

View File

@ -4009,6 +4009,19 @@ private:
// Pointer to unknown type
ASSERT_EQUALS("*", typeOf("Bar* b;", "b"));
// Enum
ASSERT_EQUALS("char", typeOf("enum E : char { }; void foo() { E e[3]; bar(e[0]); }", "[ 0"));
ASSERT_EQUALS("signed char", typeOf("enum E : signed char { }; void foo() { E e[3]; bar(e[0]); }", "[ 0"));
ASSERT_EQUALS("unsigned char", typeOf("enum E : unsigned char { }; void foo() { E e[3]; bar(e[0]); }", "[ 0"));
ASSERT_EQUALS("signed short", typeOf("enum E : short { }; void foo() { E e[3]; bar(e[0]); }", "[ 0"));
ASSERT_EQUALS("unsigned short", typeOf("enum E : unsigned short { }; void foo() { E e[3]; bar(e[0]); }", "[ 0"));
ASSERT_EQUALS("signed int", typeOf("enum E : int { }; void foo() { E e[3]; bar(e[0]); }", "[ 0"));
ASSERT_EQUALS("unsigned int", typeOf("enum E : unsigned int { }; void foo() { E e[3]; bar(e[0]); }", "[ 0"));
ASSERT_EQUALS("signed long", typeOf("enum E : long { }; void foo() { E e[3]; bar(e[0]); }", "[ 0"));
ASSERT_EQUALS("unsigned long", typeOf("enum E : unsigned long { }; void foo() { E e[3]; bar(e[0]); }", "[ 0"));
ASSERT_EQUALS("signed long long", typeOf("enum E : long long { }; void foo() { E e[3]; bar(e[0]); }", "[ 0"));
ASSERT_EQUALS("unsigned long long", typeOf("enum E : unsigned long long { }; void foo() { E e[3]; bar(e[0]); }", "[ 0"));
// Library types
{
// PodType