GCC modified for the FreeChainXenon project
Find a file
Joseph Myers e3c898e12d c: C2x auto
Implement C2x auto, a more restricted version of the C++ feature
(closer to GNU C __auto_type in terms of what's supported).

Since the feature is very close to GNU C __auto_type, much of the
implementation can be shared.  The main differences are:

* Any prior declaration of the identifier in an outer scope is
  shadowed during the initializer (whereas __auto_type leaves any such
  declaration visible until the initializer ends and the scope of the
  __auto_type declaration itself starts).  (A prior declaration in the
  same scope is undefined behavior.)

* The standard feature supports braced initializers (containing a
  single expression, optionally followed by a comma).

* The standard feature disallows the declaration from declaring
  anything that's not an ordinary identifier (thus, the initializer
  cannot declare a tag or the members of a structure or union), while
  making it undefined behavior for it to declare more than one
  ordinary identifier.  (For the latter, while I keep the existing
  error from __auto_type in the case of more than one declarator, I
  don't restrict other ordinary identifiers from being declared in
  inner scopes such as GNU statement expressions.  I do however
  disallow defining the members of an enumeration inside the
  initializer (if the enum definition has no tag, that doesn't
  actually violate a constraint), to avoid an enum type becoming
  accessible beyond where it would have been without auto.
  (Preventing new types from escaping the initializer - thus, ensuring
  that anything written with auto corresponds to something that could
  have been written without auto, modulo multiple evaluation of VLA
  size expressions when not using auto - is a key motivation for some
  restrictions on what can be declared in the initializer.)

The rule on shadowing and restrictions on other declarations in the
initializer are actually general rules for what C2x calls
underspecified declarations, a description that covers constexpr as
well as auto (in particular, this disallows a constexpr initializer
from referencing the variable being initialized).  Thus, some of the
code added for those restrictions will also be of use in implementing
C2x constexpr.

auto with a type specifier remains a storage class specifier with the
same meaning as before (i.e. a redundant storage class specifier for
use at block scope).

Note that the feature is only enabled in C2x mode (-std=c2x or
-std=gnu2x); in older modes, a declaration with auto and no type is
treated as a case of implicit int (only accepted at block scope).

Since many of the restrictions on C2x auto are specified as undefined
behavior rather than constraint violations, it would be possible to
support more features from C++ auto without requiring diagnostics (but
maybe not a good idea, if it isn't clear exactly what semantics might
be given to such a feature in a future revision of C; and
-Wc23-c2y-compat should arguably warn for any such future feature
anyway).  For now the features are limited to something close to
what's supported with __auto_type, with the differences as discussed
above between the two features.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c/
	* c-decl.cc (in_underspecified_init, start_underspecified_init)
	(finish_underspecified_init): New.
	(shadow_tag_warned, parser_xref_tag, start_struct, start_enum):
	Give errors inside initializers of underspecified declarations.
	(grokdeclarator): Handle (erroneous) case of C2X auto on a
	parameter.
	(declspecs_add_type): Handle c2x_auto_p case.
	(declspecs_add_scspec): Handle auto possibly setting c2x_auto_p in
	C2X mode.
	(finish_declspecs): Handle c2x_auto_p.
	* c-parser.cc (c_parser_declaration_or_fndef): Handle C2X auto.
	* c-tree.h (C_DECL_UNDERSPECIFIED): New macro.
	(struct c_declspecs): Add c2x_auto_p.
	(start_underspecified_init, finish_underspecified_init): New
	prototypes.
	* c-typeck.cc (build_external_ref): Give error for underspecified
	declaration referenced in its initializer.

gcc/testsuite/
	* gcc.dg/c2x-auto-1.c, gcc.dg/c2x-auto-2.c, gcc.dg/c2x-auto-3.c,
	gcc.dg/c2x-auto-4.c, gcc.dg/gnu2x-auto-1.c: New tests.
2022-11-03 02:53:41 +00:00
c++tools Daily bump. 2022-03-19 00:16:22 +00:00
config Daily bump. 2022-10-20 00:17:52 +00:00
contrib Daily bump. 2022-10-21 00:17:52 +00:00
fixincludes Daily bump. 2022-10-08 00:17:29 +00:00
gcc c: C2x auto 2022-11-03 02:53:41 +00:00
gnattools Daily bump. 2022-09-01 00:17:39 +00:00
gotools Daily bump. 2022-08-31 00:16:45 +00:00
include Daily bump. 2022-11-01 00:19:02 +00:00
INSTALL
intl Daily bump. 2021-11-30 00:16:44 +00:00
libada Daily bump. 2022-08-26 00:16:21 +00:00
libatomic Daily bump. 2022-10-20 00:17:52 +00:00
libbacktrace Daily bump. 2022-10-13 00:17:37 +00:00
libcc1 Daily bump. 2022-11-02 00:17:38 +00:00
libcody Daily bump. 2022-06-04 00:16:27 +00:00
libcpp Daily bump. 2022-10-20 00:17:52 +00:00
libdecnumber Daily bump. 2022-10-08 00:17:29 +00:00
libffi Daily bump. 2022-10-13 00:17:37 +00:00
libgcc Daily bump. 2022-10-24 00:16:31 +00:00
libgfortran Daily bump. 2022-10-13 00:17:37 +00:00
libgo runtime: use _libgo_off_t_type when calling C mmap 2022-10-27 17:12:57 -07:00
libgomp Daily bump. 2022-11-03 00:17:32 +00:00
libiberty Daily bump. 2022-10-19 00:19:08 +00:00
libitm Daily bump. 2022-11-01 00:19:02 +00:00
libobjc Daily bump. 2022-10-21 00:17:52 +00:00
liboffloadmic Daily bump. 2022-10-13 00:17:37 +00:00
libphobos Daily bump. 2022-10-30 00:16:29 +00:00
libquadmath Daily bump. 2022-10-13 00:17:37 +00:00
libsanitizer Daily bump. 2022-10-20 00:17:52 +00:00
libssp Daily bump. 2022-10-13 00:17:37 +00:00
libstdc++-v3 Daily bump. 2022-11-03 00:17:32 +00:00
libvtv Daily bump. 2022-11-01 00:19:02 +00:00
lto-plugin Daily bump. 2022-10-13 00:17:37 +00:00
maintainer-scripts Daily bump. 2022-07-29 00:16:21 +00:00
zlib Daily bump. 2022-10-13 00:17:37 +00:00
.dir-locals.el dir-locals: Use https for bug references 2021-07-20 11:40:34 +01:00
.gitattributes
.gitignore .gitignore: do not ignore config.h 2022-07-19 17:07:04 +03:00
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2022-11-01 00:19:02 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess config.sub, config.guess : Import upstream 2021-01-25. 2021-02-23 17:21:10 +08:00
config.rpath
config.sub config.sub: change mode to 755. 2021-12-21 09:10:57 +01:00
configure Don't build readline/libreadline.a, when --with-system-readline is supplied 2022-10-21 08:51:16 +02:00
configure.ac Don't build readline/libreadline.a, when --with-system-readline is supplied 2022-10-21 08:51:16 +02:00
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
depcomp
install-sh
libtool-ldflags
libtool.m4 Generic configury support for shared libs on VxWorks 2022-10-11 07:31:07 +00:00
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS Update email address 2022-10-31 11:15:45 +00:00
Makefile.def Makefile.def: drop remnants of unused libelf 2022-08-18 09:37:09 +01:00
Makefile.in Makefile.def: drop remnants of unused libelf 2022-08-18 09:37:09 +01:00
Makefile.tpl Makefile.def: drop remnants of unused libelf 2022-08-18 09:37:09 +01:00
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
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.