https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104392
Bug ID: 104392 Summary: Unexpected Narrowing Warning when spaceship comparison of unsigned bit field Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: bieri.hp at gmail dot com Target Milestone: --- struct A { unsigned int a:5; }; constexpr std::strong_ordering operator<=>(const A & left, const A & right ) { return left.a <=> right.a; } results in the unexpected warnings <source>: In function 'constexpr std::strong_ordering operator<=>(const A&, const A&)': <source>:15:21: warning: narrowing conversion of 'left.A::a' from 'const unsigned int' to 'int' [-Wnarrowing] 15 | return left.a <=> right.a; | ~~~~~^ <source>:15:33: warning: narrowing conversion of 'right.A::a' from 'const unsigned int' to 'int' [-Wnarrowing] 15 | return left.a <=> right.a; | ~~~~~~^ it seems to choose the int comparison operator although the type is unsigned