Go to file
Marek Polacek 455ade1846 c++: Deprecate arithmetic convs on different enums [PR97573]
I noticed that C++20 P1120R0 deprecated certain arithmetic conversions
as outlined in [depr.arith.conv.enum], but we don't warn about them.  In
particular, "If one operand is of enumeration type and the other operand
is of a different enumeration type or a floating-point type, this
behavior is deprecated."  These will likely become ill-formed in C++23,
so we should warn by default in C++20.  To this effect, this patch adds
two new warnings (like clang++): -Wdeprecated-enum-enum-conversion and
-Wdeprecated-enum-float-conversion.  They are enabled by default in
C++20.  In older dialects, to enable these warnings you can now use
-Wenum-conversion which I made available in C++ too.  Note that unlike
C, in C++ it is not enabled by -Wextra, because that breaks bootstrap.

We already warn about comparisons of two different enumeration types via
-Wenum-compare, the rest is handled in this patch: we're performing the
usual arithmetic conversions in these contexts:
  - an arithmetic operation,
  - a bitwise operation,
  - a comparison,
  - a conditional operator,
  - a compound assign operator.

Using the spaceship operator as enum <=> real_type is ill-formed but we
don't reject it yet.  We should also address [depr.array.comp] too, but
it's not handled in this patch.

gcc/c-family/ChangeLog:

	PR c++/97573
	* c-opts.c (c_common_post_options): In C++20, turn on
	-Wdeprecated-enum-enum-conversion and
	-Wdeprecated-enum-float-conversion.
	* c.opt (Wdeprecated-enum-enum-conversion,
	Wdeprecated-enum-float-conversion): New options.
	(Wenum-conversion): Allow for C++ too.

gcc/cp/ChangeLog:

	PR c++/97573
	* call.c (build_conditional_expr_1): Warn about the deprecated
	enum/real type conversion in C++20.  Also warn about a non-enumerated
	and enumerated type in ?: when -Wenum-conversion is on.
	* typeck.c (do_warn_enum_conversions): New function.
	(cp_build_binary_op): Call it.

gcc/ChangeLog:

	PR c++/97573
	* doc/invoke.texi: Document -Wdeprecated-enum-enum-conversion
	and -Wdeprecated-enum-float-conversion.  -Wenum-conversion is
	no longer C/ObjC only.

gcc/testsuite/ChangeLog:

	PR c++/97573
	* g++.dg/cpp0x/linkage2.C: Add dg-warning.
	* g++.dg/parse/attr3.C: Likewise.
	* g++.dg/cpp2a/enum-conv1.C: New test.
	* g++.dg/cpp2a/enum-conv2.C: New test.
	* g++.dg/cpp2a/enum-conv3.C: New test.
2020-10-28 17:37:18 -04:00
config
contrib
fixincludes
gcc c++: Deprecate arithmetic convs on different enums [PR97573] 2020-10-28 17:37:18 -04:00
gnattools
gotools
include
INSTALL
intl
libada
libatomic
libbacktrace
libcc1
libcpp
libdecnumber
libffi
libgcc Daily bump. 2020-10-28 00:16:38 +00:00
libgfortran
libgo syscall: don't build libcall_bsd.go on solaris 2020-10-28 12:18:01 -07:00
libgomp openmp: Implicitly discover declare target for variants of declare variant calls 2020-10-28 10:36:31 +01:00
libhsail-rt
libiberty
libitm
libobjc
liboffloadmic
libphobos Daily bump. 2020-10-28 00:16:38 +00:00
libquadmath
libsanitizer
libssp
libstdc++-v3 libstdc++: Implement C++20 features for <sstream> 2020-10-28 11:56:06 -07:00
libvtv
lto-plugin
maintainer-scripts
zlib
.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
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS
Makefile.def
Makefile.in
Makefile.tpl
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.