]> gcc.gnu.org Git - gcc.git/commit
c++: fix 'unsigned typedef-name' extension [PR108099]
authorJason Merrill <jason@redhat.com>
Wed, 19 Apr 2023 01:32:07 +0000 (21:32 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 21 Apr 2023 19:33:32 +0000 (15:33 -0400)
commit03cebd304955a6b9c5607e09312d77f1307cc98e
treecc7cd658db9db4babe1ec1c9a5c09e3107844f28
parent7d115e014111565653b3e716bb2911c0016838e5
c++: fix 'unsigned typedef-name' extension [PR108099]

In the comments for PR108099 Jakub provided some testcases that demonstrated
that even before the regression noted in the patch we were getting the
semantics of this extension wrong: in the unsigned case we weren't producing
the corresponding standard unsigned type but another distinct one of the
same size, and in the signed case we were just dropping it on the floor and
not actually returning a signed type at all.

The former issue is fixed by using c_common_signed_or_unsigned_type instead
of unsigned_type_for, and the latter issue by adding a (signed_p &&
typedef_decl) case.

This patch introduces a failure on std/ranges/iota/max_size_type.cc due to
the latter issue, since the testcase expects 'signed rep_t' to do something
sensible, and previously we didn't.  Now that we do, it exposes a bug in the
__max_diff_type::operator>>= handling of sign extension: when we evaluate
-1000 >> 2 in __max_diff_type we keep the MSB set, but leave the
second-most-significant bit cleared.

PR c++/108099

gcc/cp/ChangeLog:

* decl.cc (grokdeclarator): Don't clear typedef_decl after 'unsigned
typedef' pedwarn.  Use c_common_signed_or_unsigned_type.  Also
handle 'signed typedef'.

gcc/testsuite/ChangeLog:

* g++.dg/ext/int128-8.C: Remove xfailed dg-bogus markers.
* g++.dg/ext/unsigned-typedef2.C: New test.
* g++.dg/ext/unsigned-typedef3.C: New test.
gcc/cp/decl.cc
gcc/testsuite/g++.dg/ext/int128-8.C
gcc/testsuite/g++.dg/ext/unsigned-typedef2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/unsigned-typedef3.C [new file with mode: 0644]
This page took 0.065602 seconds and 6 git commands to generate.