![]() Changed in v2: - distinguish between "bool" and "_Bool" when determining standard version 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. 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 gcc/c/ChangeLog: PR c/117629 * c-decl.cc (declspecs_add_type): Special-case attempts to use bool as a typedef name or declaration name. * c-errors.cc (get_std_for_keyword): New. (add_note_about_new_keyword): New. * c-parser.cc (report_bad_enum_name): New, split out from... (c_parser_enum_specifier): ...here, adding handling for RID_FALSE and RID_TRUE. * c-tree.h (add_note_about_new_keyword): New decl. gcc/testsuite/ChangeLog: PR c/117629 * gcc.dg/auto-type-2.c: Update expected output with _Bool. * gcc.dg/c23-bool-errors-1.c: New test. * gcc.dg/c23-bool-errors-2.c: New test. * gcc.dg/c23-bool-errors-3.c: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com> |
||
---|---|---|
.forgejo | ||
.github | ||
c++tools | ||
config | ||
contrib | ||
fixincludes | ||
gcc | ||
gnattools | ||
gotools | ||
include | ||
INSTALL | ||
libada | ||
libatomic | ||
libbacktrace | ||
libcc1 | ||
libcody | ||
libcpp | ||
libdecnumber | ||
libffi | ||
libgcc | ||
libgfortran | ||
libgm2 | ||
libgo | ||
libgomp | ||
libgrust | ||
libiberty | ||
libitm | ||
libobjc | ||
libphobos | ||
libquadmath | ||
libsanitizer | ||
libssp | ||
libstdc++-v3 | ||
libvtv | ||
lto-plugin | ||
maintainer-scripts | ||
zlib | ||
.b4-config | ||
.dir-locals.el | ||
.gitattributes | ||
.gitignore | ||
ABOUT-NLS | ||
ar-lib | ||
ChangeLog | ||
ChangeLog.jit | ||
ChangeLog.tree-ssa | ||
compile | ||
config-ml.in | ||
config.guess | ||
config.rpath | ||
config.sub | ||
configure | ||
configure.ac | ||
COPYING | ||
COPYING.LIB | ||
COPYING.RUNTIME | ||
COPYING3 | ||
COPYING3.LIB | ||
depcomp | ||
install-sh | ||
libtool-ldflags | ||
libtool.m4 | ||
ltgcc.m4 | ||
ltmain.sh | ||
ltoptions.m4 | ||
ltsugar.m4 | ||
ltversion.m4 | ||
lt~obsolete.m4 | ||
MAINTAINERS | ||
Makefile.def | ||
Makefile.in | ||
Makefile.tpl | ||
missing | ||
mkdep | ||
mkinstalldirs | ||
move-if-change | ||
multilib.am | ||
README | ||
SECURITY.txt | ||
symlink-tree | ||
test-driver | ||
ylwrap |
This directory contains the GNU Compiler Collection (GCC). The GNU Compiler Collection is free software. See the files whose names start with COPYING for copying permission. The manuals, and some of the runtime libraries, are under different terms; see the individual source files for details. The directory INSTALL contains copies of the installation information as HTML and plain text. The source of this information is gcc/doc/install.texi. The installation information includes details of what is included in the GCC sources and what files GCC installs. See the file gcc/doc/gcc.texi (together with other files that it includes) for usage and porting information. An online readable version of the manual is in the files gcc/doc/gcc.info*. See http://gcc.gnu.org/bugs/ for how to report bugs usefully. Copyright years on GCC source files may be listed using range notation, e.g., 1987-2012, indicating that every year in the range, inclusive, is a copyrightable year that could otherwise be listed individually.