Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7550,10 +7550,13 @@ static const Token* parsedecl(const Token* type,
else if (valuetype->typeScope->type == ScopeType::eEnum) {
const Token * enum_type = valuetype->typeScope->enumType;
if (enum_type) {
ValueType evt;
if (enum_type->isSigned())
valuetype->sign = ValueType::Sign::SIGNED;
else if (enum_type->isUnsigned())
valuetype->sign = ValueType::Sign::UNSIGNED;
else if (!enum_type->isStandardType() && parsedecl(enum_type, &evt, defaultSignedness, settings))
*valuetype = evt;
else
valuetype->sign = defaultSignedness; // TODO: this is implementation-dependent might be separate from char
const ValueType::Type t = ValueType::typeFromString(enum_type->str(), enum_type->isLong());
Expand Down Expand Up @@ -7728,8 +7731,10 @@ static const Token* parsedecl(const Token* type,
valuetype->type = type->str() == "struct" ? ValueType::Type::RECORD : ValueType::Type::NONSTD;
else if (!valuetype->typeScope && type->type() && type->type()->classScope && valuetype->type != ValueType::Type::SMART_POINTER) {
if (type->type()->classScope->type == ScopeType::eEnum) {
valuetype->sign = ValueType::Sign::SIGNED;
valuetype->type = getEnumType(type->type()->classScope, settings.platform);
if (valuetype->type == ValueType::Type::UNKNOWN_TYPE) {
valuetype->sign = ValueType::Sign::SIGNED;
valuetype->type = getEnumType(type->type()->classScope, settings.platform);
}
} else {
valuetype->type = ValueType::Type::RECORD;
}
Expand Down
7 changes: 7 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6650,6 +6650,13 @@ class TestCondition : public TestFixture {
"[test.cpp:2:28]: (style) Comparing expression of type 'signed int' against value 2147483647. Condition is always false. [compareValueOutOfTypeRangeError]\n"
"[test.cpp:7:17]: (style) Comparing expression of type 'signed int' against value 2147483647. Condition is always false. [compareValueOutOfTypeRangeError]\n",
errout_str());

check("enum E : std::uint8_t {};\n" // #11243
"void f(E e) {\n"
" if (e == 256) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3:14]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\n",
errout_str());
}

void knownConditionCast() {
Expand Down
5 changes: 2 additions & 3 deletions test/testio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3497,9 +3497,8 @@ class TestIO : public TestFixture {
"void f(E e) {\n"
" printf(\"%lu\", e);\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'uint8_t'.\n",
"",
errout_str());
ASSERT_EQUALS("[test.cpp:3]: (warning) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'unsigned char'.\n",
errout_str());

check("void f() {\n"
" printf(\"%lu\", sizeof(char));\n"
Expand Down
Loading