Skip to content
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