Repository navigation
Fix #11243 FN: knownConditionTrueFalse (range of typed enum) #8930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
130cc52
ad8a76d
4125d4b
8add06a
1b060fc
f24d711
0113da7
a153571
7ef100a
cabe20e
759a3d7
30df97b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7554,8 +7554,13 @@ static const Token* parsedecl(const Token* type, | |
| valuetype->sign = ValueType::Sign::SIGNED; | ||
| else if (enum_type->isUnsigned()) | ||
| valuetype->sign = ValueType::Sign::UNSIGNED; | ||
| else | ||
| valuetype->sign = defaultSignedness; // TODO: this is implementation-dependent might be separate from char | ||
| else if (!enum_type->isStandardType()) { | ||
| ValueType evt; | ||
| if (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()); | ||
| if (t != ValueType::Type::UNKNOWN_TYPE) | ||
| valuetype->type = t; | ||
|
|
@@ -7728,13 +7733,15 @@ 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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI review Keeping the unsigned underlying type here makes enum class Color : std::uint8_t { Red, Green, Blue };
bool isFirst(Color c) { return c <= Color::Red; } // unsignedLessThanZero: Checking if unsigned expression 'c' is less than zero.
enum class U : unsigned { Red, Green };
bool isValid3(U c) { return c >= U::Red; } // unsignedPositive: Unsigned expression 'c' can't be negative ...
for (Color c = Color::Blue; c >= Color::Red; ...) // unsignedPositiveIt also affects I think these are false positives. The enumerator is zero only because it is declared first, the comparison is written in terms of enumerators and not Please consider skipping these checks when the zero operand is an enumerator, or when the other operand has an enum |
||
| valuetype->sign = ValueType::Sign::SIGNED; | ||
| valuetype->type = getEnumType(type->type()->classScope, settings.platform); | ||
| } | ||
| } else { | ||
| valuetype->type = ValueType::Type::RECORD; | ||
| } | ||
| valuetype->typeScope = type->type()->classScope; | ||
| } else if (type->isName() && valuetype->sign != ValueType::Sign::UNKNOWN_SIGN && valuetype->pointer == 0U) | ||
| } else if (type->isNameOnly() && valuetype->sign != ValueType::Sign::UNKNOWN_SIGN && valuetype->pointer == 0U) | ||
| return nullptr; | ||
| else if (Token::Match(type->previous(), "!!:: %name% !!::")) { | ||
| if (!type->isKeyword()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI review
This edit and the one in
gui/mainwindow.cpplook like workarounds for the newunsignedLessThanZerothat the PR produces onx <= Enum::FirstValue. User code with the same pattern will get the same warning (reproduced, see the comment insymboldatabase.cpp).The original
<= Standards::CPP03was reasonable code. I would treat the need to rewrite it as a sign that the warning should be suppressed for enumerators, not as something to fix at each use.