Sam James <s...@gentoo.org> writes: > David Malcolm <dmalc...@redhat.com> writes: > >> On Tue, 2024-11-26 at 16:35 -0500, Marek Polacek wrote: >>> On Mon, Nov 25, 2024 at 10:49:02PM -0500, David Malcolm wrote: >>> > This patch attempts to provide better error messages for >>> > code compiled with C23 that hasn't been updated for >>> > "bool", "true", and "false" becoming keywords (based on >>> > a brief review of the Gentoo bug tracker links given at >>> > https://gcc.gnu.org/pipermail/gcc/2024-November/245185.html). >>> > >>> > Specifically: >>> > >>> > (1) with "typedef int bool;" previously we emitted: >>> > >>> > t1.c:7:13: error: two or more data types in declaration specifiers >>> > 7 | typedef int bool; >>> > | ^~~~ >>> > t1.c:7:1: warning: useless type name in empty declaration >>> > 7 | typedef int bool; >>> > | ^~~~~~~ >>> > >>> > whereas with this patch we emit: >>> > >>> > t1.c:7:13: error: 'bool' cannot be defined via 'typedef' >>> > 7 | typedef int bool; >>> > | ^~~~ >>> > t1.c:7:13: note: 'bool' is a keyword with '-std=c23' onwards >>> > t1.c:7:1: warning: useless type name in empty declaration >>> > 7 | typedef int bool; >>> > | ^~~~~~~ >>> > >>> > (2) with "int bool;" previously we emitted: >>> > >>> > t2.c:7:5: error: two or more data types in declaration specifiers >>> > 7 | int bool; >>> > | ^~~~ >>> > t2.c:7:1: warning: useless type name in empty declaration >>> > 7 | int bool; >>> > | ^~~ >>> > >>> > whereas with this patch we emit: >>> > >>> > t2.c:7:5: error: 'bool' cannot be used here >>> > 7 | int bool; >>> > | ^~~~ >>> > t2.c:7:5: note: 'bool' is a keyword with '-std=c23' onwards >>> > t2.c:7:1: warning: useless type name in empty declaration >>> > 7 | int bool; >>> > | ^~~ >>> > >>> > (3) with "typedef enum { false = 0, true = 1 } _Bool;" previously >>> > we >>> > emitted: >>> > >>> > t3.c:7:16: error: expected identifier before 'false' >>> > 7 | typedef enum { false = 0, true = 1 } _Bool; >>> > | ^~~~~ >>> > t3.c:7:38: error: expected ';', identifier or '(' before '_Bool' >>> > 7 | typedef enum { false = 0, true = 1 } _Bool; >>> > | ^~~~~ >>> > t3.c:7:38: warning: useless type name in empty declaration >>> > >>> > whereas with this patch we emit: >>> > >>> > t3.c:7:16: error: cannot use keyword 'false' as enumeration >>> > constant >>> > 7 | typedef enum { false = 0, true = 1 } _Bool; >>> > | ^~~~~ >>> > t3.c:7:16: note: 'false' is a keyword with '-std=c23' onwards >>> > t3.c:7:38: error: expected ';', identifier or '(' before '_Bool' >>> > 7 | typedef enum { false = 0, true = 1 } _Bool; >>> > | ^~~~~ >>> > t3.c:7:38: warning: useless type name in empty declaration >>> > >>> > >>> > Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. >>> > OK for trunk? >>> >>> Thanks for the patch. >>> >>> For: >>> >>> typedef int _Bool; >>> >>> or >>> >>> int _Bool; >>> >>> this patch says: >>> >>> note: '_Bool' is a keyword with '-std=c23' onwards >>> >>> but I don't think that's true: _Bool was added in C99 and is >>> obsolescent in >>> C23. >> >> Is _Bool meant to be usable in c90? >> >> I tried with -std=c90 and it fails; see: >> https://godbolt.org/z/Wf6a9EKP9 > > No, it's not: it was introducd in C99.
Ignore me and listen to Andrew ;) Filed https://gcc.gnu.org/PR118118 for the docs. > >> >> <source>:1:13: error: two or more data types in declaration specifiers >> 1 | typedef int _Bool; >> | ^~~~~ >> <source>:1:1: warning: useless type name in empty declaration >> 1 | typedef int _Bool; >> | ^~~~~~~ >> >> Thanks >> Dave