]> gcc.gnu.org Git - gcc.git/commit
c++: DR2627, Bit-fields and narrowing conversions [PR94058]
authorMarek Polacek <polacek@redhat.com>
Fri, 28 Jun 2024 21:51:19 +0000 (17:51 -0400)
committerMarek Polacek <polacek@redhat.com>
Mon, 1 Jul 2024 18:32:41 +0000 (14:32 -0400)
commit52d71b6b1f0f465a6cf064f61b22fc99453ec132
tree8eb0f6c97deea03b29b19b260e62e2398a3eb7af
parent4d24159a1fcb15e1e28f46aa418de5e1ae384ff5
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.
gcc/cp/typeck2.cc
gcc/testsuite/g++.dg/DRs/dr2627.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/Wnarrowing22.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/spaceship-narrowing1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/spaceship-narrowing2.C [new file with mode: 0644]
This page took 0.071509 seconds and 6 git commands to generate.