public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* _BitInt() as underlying enum type
@ 2024-01-28 2:06 Thomas Voss
2024-01-28 2:24 ` Andrew Pinski
0 siblings, 1 reply; 4+ messages in thread
From: Thomas Voss @ 2024-01-28 2:06 UTC (permalink / raw)
To: gcc-bugs
Hi all,
Earlier today I decided to clone the GCC repo and build the latest code
just to play around with some new C23 features. One thing I attempted
was the following:
typedef _BitInt(128) underlying;
enum my_enum : underlying {
FOO = (underlying)1 << 100;
BAR = (underlying)1 << 101;
};
I expected this to work — it builds on Clang too — but it failed to
compile with the error ‘invalid underlying type’ (or something like that;
I’m going off of memory).
I took a look into the C23 working draft and I see no reference to
bit-precise integers being disallowed as an underlying type to an
enumeration. As a result I assume this is a bug in GCC so I’m reporting
it here just in case. If it’s not a bug, do let me know why that is the
case.
--
— Thomas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: _BitInt() as underlying enum type
2024-01-28 2:06 _BitInt() as underlying enum type Thomas Voss
@ 2024-01-28 2:24 ` Andrew Pinski
2024-01-28 4:25 ` Andrew Pinski
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Pinski @ 2024-01-28 2:24 UTC (permalink / raw)
To: Thomas Voss; +Cc: gcc-bugs
On Sat, Jan 27, 2024 at 6:07 PM Thomas Voss via Gcc-bugs
<gcc-bugs@gcc.gnu.org> wrote:
>
> Hi all,
>
> Earlier today I decided to clone the GCC repo and build the latest code
> just to play around with some new C23 features. One thing I attempted
> was the following:
>
> typedef _BitInt(128) underlying;
> enum my_enum : underlying {
> FOO = (underlying)1 << 100;
> BAR = (underlying)1 << 101;
> };
>
> I expected this to work — it builds on Clang too — but it failed to
> compile with the error ‘invalid underlying type’ (or something like that;
> I’m going off of memory).
The trunk of clang rejects it:
```
<source>:4:20: error: 'underlying' (aka '_BitInt(128)') is an invalid
underlying type
4 | enum my_enum : underlying {
| ^
```
While clang 17.0 accepts it. So it looks like clang fixed their bug.
Thanks,
Andrew
>
> I took a look into the C23 working draft and I see no reference to
> bit-precise integers being disallowed as an underlying type to an
> enumeration. As a result I assume this is a bug in GCC so I’m reporting
> it here just in case. If it’s not a bug, do let me know why that is the
> case.
>
> --
> — Thomas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: _BitInt() as underlying enum type
2024-01-28 2:24 ` Andrew Pinski
@ 2024-01-28 4:25 ` Andrew Pinski
2024-01-28 13:56 ` Jakub Jelinek
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Pinski @ 2024-01-28 4:25 UTC (permalink / raw)
To: Thomas Voss; +Cc: gcc-bugs
On Sat, Jan 27, 2024 at 6:24 PM Andrew Pinski <pinskia@gmail.com> wrote:
>
> On Sat, Jan 27, 2024 at 6:07 PM Thomas Voss via Gcc-bugs
> <gcc-bugs@gcc.gnu.org> wrote:
> >
> > Hi all,
> >
> > Earlier today I decided to clone the GCC repo and build the latest code
> > just to play around with some new C23 features. One thing I attempted
> > was the following:
> >
> > typedef _BitInt(128) underlying;
> > enum my_enum : underlying {
> > FOO = (underlying)1 << 100;
> > BAR = (underlying)1 << 101;
> > };
> >
> > I expected this to work — it builds on Clang too — but it failed to
> > compile with the error ‘invalid underlying type’ (or something like that;
> > I’m going off of memory).
>
> The trunk of clang rejects it:
> ```
> <source>:4:20: error: 'underlying' (aka '_BitInt(128)') is an invalid
> underlying type
> 4 | enum my_enum : underlying {
> | ^
> ```
> While clang 17.0 accepts it. So it looks like clang fixed their bug.
Just an FYI, the clang issue was
https://github.com/llvm/llvm-project/issues/69619 .
With the following commit to the LLVM git repo as the fix:
https://github.com/llvm/llvm-project/commit/5175cd777c57190ab9860c304796d386e4df9b8f
>
> Thanks,
> Andrew
>
> >
> > I took a look into the C23 working draft and I see no reference to
> > bit-precise integers being disallowed as an underlying type to an
> > enumeration. As a result I assume this is a bug in GCC so I’m reporting
> > it here just in case. If it’s not a bug, do let me know why that is the
> > case.
> >
> > --
> > — Thomas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: _BitInt() as underlying enum type
2024-01-28 4:25 ` Andrew Pinski
@ 2024-01-28 13:56 ` Jakub Jelinek
0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2024-01-28 13:56 UTC (permalink / raw)
To: Andrew Pinski; +Cc: Thomas Voss, gcc-bugs
On Sat, Jan 27, 2024 at 08:25:04PM -0800, Andrew Pinski via Gcc-bugs wrote:
> Just an FYI, the clang issue was
> https://github.com/llvm/llvm-project/issues/69619 .
> With the following commit to the LLVM git repo as the fix:
> https://github.com/llvm/llvm-project/commit/5175cd777c57190ab9860c304796d386e4df9b8f
Indeed, the C23 draft I have specifies in 6.7.2.2/5:
"If an enum type specifier is present, then the longest possible sequence of tokens that can be
interpreted as a specifier qualifier list is interpreted as part of the enum type specifier. It shall name
an integer type that is neither an enumeration nor a bit-precise integer
type."
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-01-28 13:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-28 2:06 _BitInt() as underlying enum type Thomas Voss
2024-01-28 2:24 ` Andrew Pinski
2024-01-28 4:25 ` Andrew Pinski
2024-01-28 13:56 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).