Skip to content

[NFC] Replace bool <= bool comparison #102948

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

Merged
merged 1 commit into from
Aug 22, 2024
Merged
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
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ NarrowingKind StandardConversionSequence::getNarrowingKind(
constexpr auto CanRepresentAll = [](bool FromSigned, unsigned FromWidth,
bool ToSigned, unsigned ToWidth) {
return (FromWidth < ToWidth + (FromSigned == ToSigned)) &&
(FromSigned <= ToSigned);
!(FromSigned && !ToSigned);
};

if (CanRepresentAll(FromSigned, FromWidth, ToSigned, ToWidth))
Expand Down Expand Up @@ -542,7 +542,7 @@ NarrowingKind StandardConversionSequence::getNarrowingKind(
// If the bit-field width was dependent, it might end up being small
// enough to fit in the target type (unless the target type is unsigned
// and the source type is signed, in which case it will never fit)
if (DependentBitField && (FromSigned <= ToSigned))
if (DependentBitField && !(FromSigned && !ToSigned))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be

Suggested change
if (DependentBitField && !(FromSigned && !ToSigned))
if (DependentBitField && (!FromSigned || ToSigned))

But the way written follows the comment exactly and should optimise the same

return NK_Dependent_Narrowing;

// Otherwise, such a conversion is always narrowing
Expand Down
Loading