[Bug c++/104392] Unexpected Narrowing Warning when spaceship comparison of unsigned bit field
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Jul 1 18:33:03 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104392
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:52d71b6b1f0f465a6cf064f61b22fc99453ec132
commit r15-1758-g52d71b6b1f0f465a6cf064f61b22fc99453ec132
Author: Marek Polacek <polacek@redhat.com>
Date: Fri Jun 28 17:51:19 2024 -0400
c++: DR2627, Bit-fields and narrowing conversions [PR94058]
This DR (https://cplusplus.github.io/CWG/issues/2627.html) says that
even if we are converting from an integer type or unscoped enumeration type
to an integer type that cannot represent all the values of the original
type, it's not narrowing if "the source is a bit-field whose width w is
less than that of its type (or, for an enumeration type, its underlying
type) and the target type can represent all the values of a hypothetical
extended integer type with width w and with the same signedness as the
original type".
DR 2627
PR c++/94058
PR c++/104392
gcc/cp/ChangeLog:
* typeck2.cc (check_narrowing): Don't warn if the conversion isn't
narrowing as per DR 2627.
gcc/testsuite/ChangeLog:
* g++.dg/DRs/dr2627.C: New test.
* g++.dg/cpp0x/Wnarrowing22.C: New test.
* g++.dg/cpp2a/spaceship-narrowing1.C: New test.
* g++.dg/cpp2a/spaceship-narrowing2.C: New test.
More information about the Gcc-bugs
mailing list