Skip to content
Snippets Groups Projects
Commit 0cf68222 authored by Joseph Myers's avatar Joseph Myers
Browse files

c: Add -std=c2y, -std=gnu2y, -Wc23-c2y-compat, C2Y _Generic with type operand

The first new C2Y feature, _Generic where the controlling operand is a
type name rather than an expression (as defined in N3260), was voted
into C2Y today.  (In particular, this form of _Generic allows
distinguishing qualified and unqualified versions of a type.)  This
feature also includes allowing the generic associations to specify
incomplete and function types.

Add this feature to GCC, along with the -std=c2y, -std=gnu2y and
-Wc23-c2y-compat options to control when and how it is diagnosed.  As
usual, the feature is allowed by default in older standards modes,
subject to diagnosis with -pedantic, -pedantic-errors or
-Wc23-c2y-compat.

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

gcc/
	* doc/cpp.texi (__STDC_VERSION__): Document C2Y handling.
	* doc/invoke.texi (-Wc23-c2y-compat, -std=c2y, -std=gnu2y):
	Document options.
	(-std=gnu23): Update documentation.
	* doc/standards.texi (C Language): Document C2Y.  Update C23
	description.
	* config/rl78/rl78.cc (rl78_option_override): Handle "GNU C2Y"
	language name.
	* dwarf2out.cc (highest_c_language, gen_compile_unit_die):
	Likewise.

gcc/c-family/
	* c-common.cc (flag_isoc2y): New.
	(flag_isoc99, flag_isoc11, flag_isoc23): Update comments.
	* c-common.h (flag_isoc2y): New.
	(clk_c, flag_isoc23): Update comments.
	* c-opts.cc (set_std_c2y): New.
	(c_common_handle_option): Handle OPT_std_c2y and OPT_std_gnu2y.
	(set_std_c89, set_std_c99, set_std_c11, set_std_c17, set_std_c23):
	Set flag_isoc2y.
	(set_std_c23): Update comment.
	* c.opt (Wc23-c2y-compat, std=c2y, std=gnu2y): New.
	* c.opt.urls: Regenerate.

gcc/c/
	* c-errors.cc (pedwarn_c23): New.
	* c-parser.cc (disable_extension_diagnostics)
	(restore_extension_diagnostics): Save and restore
	warn_c23_c2y_compat.
	(c_parser_generic_selection): Handle type name as controlling
	operand.  Allow incomplete and function types subject to
	pedwarn_c23 calls.
	* c-tree.h (pedwarn_c23): New.

gcc/testsuite/
	* gcc.dg/c23-generic-1.c, gcc.dg/c23-generic-2.c,
	gcc.dg/c23-generic-3.c, gcc.dg/c23-generic-4.c,
	gcc.dg/c2y-generic-1.c, gcc.dg/c2y-generic-2.c,
	gcc.dg/c2y-generic-3.c, gcc.dg/gnu2y-generic-1.c: New tests.
	* gcc.dg/c23-tag-6.c: Use -pedantic-errors.

libcpp/
	* include/cpplib.h (CLK_GNUC2Y, CLK_STDC2Y): New.
	* init.cc (lang_defaults): Add GNUC2Y and STDC2Y entries.
	(cpp_init_builtins): Define __STDC_VERSION__ to 202500L for GNUC2Y
	and STDC2Y.
parent 6bc26cce
No related branches found
No related tags found
No related merge requests found
Showing
with 292 additions and 39 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment