Skip to content
Snippets Groups Projects
Commit 5f580e24 authored by Jakub Jelinek's avatar Jakub Jelinek
Browse files

c++: Implement C++26 P2864R2 - Remove Deprecated Arithmetic Conversion on Enumerations From C++26

The following patch implements C++26 P2864R2 by emitting pedwarn enabled by
the same options as the C++20 and later warnings (i.e. -Wenum-compare,
-Wdeprecated-enum-enum-conversion and -Wdeprecated-enum-float-conversion
which are all enabled by default).  I think we still want to allow users
some option workaround, so am not using directly error.  Additionally, for
cxx_dialect >= cxx26 && (complain & tf_warning_or_error) == 0 it causes for
these newly ill-formed constructs error_mark_node to be silently returned.

2023-11-15  Jakub Jelinek  <jakub@redhat.com>

gcc/cp/
	* typeck.cc: Implement C++26 P2864R2 - Remove Deprecated Arithmetic
	Conversion on Enumerations From C++26.
	(do_warn_enum_conversions): Return bool rather than void, add COMPLAIN
	argument.  Use pedwarn rather than warning_at for C++26 and remove
	" is deprecated" part of the diagnostics in that case.  For SFINAE
	in C++26 return true on newly erroneous cases.
	(cp_build_binary_op): For C++26 call do_warn_enum_conversions
	unconditionally, pass complain argument to it and if it returns true,
	return error_mark_node.
	* call.cc (build_conditional_expr): Use pedwarn rather than warning_at
	for C++26 and remove " is deprecated" part of the diagnostics in that
	case and check for complain & tf_warning_or_error.  Use emit_diagnostic
	with cxx_dialect >= cxx26 ? DK_PEDWARN : DK_WARNING.  For SFINAE in
	C++26 return error_mark_node on newly erroneous cases.
	(build_new_op): Use emit_diagnostic with cxx_dialect >= cxx26
	? DK_PEDWARN : DK_WARNING and complain & tf_warning_or_error check
	for C++26.  For SFINAE in C++26 return error_mark_node on newly
	erroneous cases.
gcc/testsuite/
	* g++.dg/cpp26/enum-conv1.C: New test.
	* g++.dg/cpp2a/enum-conv1.C: Adjust expected diagnostics in C++26.
	* g++.dg/diagnostic/enum3.C: Likewise.
	* g++.dg/parse/attr3.C: Likewise.
	* g++.dg/cpp0x/linkage2.C: Likewise.
parent 081fddbb
No related branches found
No related tags found
No related merge requests found
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