mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 23:25:24 +02:00
1b876bdffd875ce061b35c7bb73f76a9bf7ec9f2
As noted in bug 88642, the C front end fails to give errors or pedwarns for scalar initializers with too many levels of surrounding braces. There is a warning for redundant braces around a scalar initializer within a larger braced initializer (valid for a single such level within a structure, union or array initializer; not valid for more than one such level, or where the outer layer of braces is itself for a scalar, either redundant braces themselves or part of a compound literal), but this never becomes an error even for invalid cases. Check for this case and turn the warning into a permerror when there are more levels of braces than permitted. The existing warning is unchanged for a single (permitted) level of redundant braces around a scalar initializer inside a structure, union or array initializer, and it's also unchanged that no such warning is given for a single (permitted) level of redundant braces around a top-level scalar initializer. Technically this is a C2y issue (these rules on valid initializers moved into Constraints as a result of N3346, accepted in Minneapolis; previously, as a "shall" outside constraints, violating these rules resulted in compile-time undefined behavior without requiring a diagnostic). Hopefully little code is actually relying on not getting an error here. In view of gcc.dg/tree-ssa/ssa-dse-10.c showing that at least some code may be using such over-braced initializers (initializer of pubKeys at line 1167 in that test; I'm not at all sure how that initializer ends up getting interpreted to translate it to something equivalent but properly structured), this is made a permerror rather than a hard error, so -fpermissive (as already used by that test) can be used to disable the error (the default -fpermissive for old standards modes is not a problem given that before C2y this is undefined behavior not a constraint violation). Bootstrapped with no regressions for x86_64-pc-linux-gnu. PR c/88642 gcc/c/ * c-typeck.cc (constructor_braced_scalar): New variable. (struct constructor_stack): Add braced_scalar field. (really_start_incremental_init): Handle constructor_braced_scalar and braced_scalar field. (push_init_level): Handle constructor_braced_scalar and braced_scalar field. Give permerror rather than warning for nested braces around scalar initializer. (pop_init_level): Handle constructor_braced_scalar and braced_scalar field. gcc/testsuite/ * gcc.dg/c2y-init-1.c: New test.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
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.
Description
Languages
C++
30.8%
C
30.2%
Ada
14.4%
D
6.1%
Go
5.7%
Other
12.3%