Skip to content

Commit db09152

Browse files
authored
Merge 2023-11 CWG Motion 4
P2864R2 Remove Deprecated Arithmetic Conversion on Enumerations From C++26
2 parents 3f1be09 + 15b77ba commit db09152

File tree

4 files changed

+56
-30
lines changed

4 files changed

+56
-30
lines changed

source/compatibility.tex

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@
1313

1414
\rSec2[diff.cpp23.expr]{\ref{expr}: expressions}
1515

16+
\diffref{expr.arith.conv}
17+
\change
18+
Operations mixing a value of an enumeration type and a value of a different
19+
enumeration type or of a floating-point type are no longer valid.
20+
\rationale
21+
Reinforcing type safety.
22+
\effect
23+
A valid \CppXXIII{} program that performs operations mixing a value of an
24+
enumeration type and a value of a different enumeration type or of a
25+
floating-point type is ill-formed.
26+
For example:
27+
\begin{codeblock}
28+
enum E1 { e };
29+
enum E2 { f };
30+
bool b = e <= 3.7; // ill-formed; previously well-formed
31+
int k = f - e; // ill-formed; previously well-formed
32+
auto x = true ? e : f; // ill-formed; previously well-formed
33+
\end{codeblock}
34+
35+
\rSec2[diff.cpp23.dcl.dcl]{\ref{dcl.dcl}: Declarations}
36+
1637
\diffref{dcl.init.list}
1738
\change
1839
Pointer comparisons between \tcode{initializer_list} objects' backing arrays
@@ -31,8 +52,6 @@
3152
bool b = ne({2,3}, {1,2,3}); // unspecified result; previously \tcode{false}
3253
\end{codeblock}
3354

34-
\rSec2[diff.cpp23.dcl.dcl]{\ref{dcl.dcl}: Declarations}
35-
3655
\diffref{dcl.array}
3756
\change
3857
Previously, \tcode{T...[n]} would declare a pack of function parameters.
@@ -2522,6 +2541,35 @@
25222541
Some ISO C translators will give a warning
25232542
if the cast is not used.
25242543

2544+
\diffref{expr.arith.conv}
2545+
\change
2546+
Operations mixing a value of an enumeration type and a value of a different
2547+
enumeration type or of a floating-point type are not valid.
2548+
For example:
2549+
\begin{codeblock}
2550+
enum E1 { e };
2551+
enum E2 { f };
2552+
int b = e <= 3.7; // valid in C; ill-formed in \Cpp{}
2553+
int k = f - e; // valid in C; ill-formed in \Cpp{}
2554+
int x = 1 ? e : f; // valid in C; ill-formed in \Cpp{}
2555+
\end{codeblock}
2556+
\rationale
2557+
Reinforcing type safety in \Cpp{}.
2558+
\effect
2559+
Well-formed C code will not compile with this International Standard.
2560+
\difficulty
2561+
Violations will be diagnosed by the \Cpp{} translator.
2562+
The original behavior can be restored with a cast or integral promotion.
2563+
For example:
2564+
\begin{codeblock}
2565+
enum E1 { e };
2566+
enum E2 { f };
2567+
int b = (int)e <= 3.7;
2568+
int k = +f - e;
2569+
\end{codeblock}
2570+
\howwide
2571+
Uncommon.
2572+
25252573
\diffref{expr.post.incr,expr.pre.incr}
25262574
\change
25272575
Decrement operator is not allowed with \keyword{bool} operand.

source/expressions.tex

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,9 @@
11441144
\item If either operand is of scoped enumeration type\iref{dcl.enum}, no conversions
11451145
are performed; if the other operand does not have the same type, the expression is
11461146
ill-formed.
1147+
\item Otherwise, if one operand is of enumeration type and the other operand is
1148+
of a different enumeration type or a floating-point type, the expression is
1149+
ill-formed.
11471150
\item Otherwise, if either operand is of floating-point type,
11481151
the following rules are applied:
11491152
\begin{itemize}
@@ -1197,13 +1200,6 @@
11971200
\end{itemize}
11981201
\end{itemize}
11991202

1200-
\pnum
1201-
If one operand is of enumeration type
1202-
and the other operand is of
1203-
a different enumeration type or
1204-
a floating-point type,
1205-
this behavior is deprecated\iref{depr.arith.conv.enum}.
1206-
12071203
\rSec1[expr.prim]{Primary expressions}%
12081204
\indextext{expression!primary|(}
12091205

source/future.tex

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,6 @@
1616
An implementation may declare library names and entities described in this Clause with the
1717
\tcode{deprecated} attribute\iref{dcl.attr.deprecated}.
1818

19-
\rSec1[depr.arith.conv.enum]{Arithmetic conversion on enumerations}
20-
21-
\pnum
22-
The ability to apply the usual arithmetic conversions\iref{expr.arith.conv}
23-
on operands where one is of enumeration type
24-
and the other is of a different enumeration type
25-
or a floating-point type
26-
is deprecated.
27-
\begin{note}
28-
Three-way comparisons\iref{expr.spaceship} between such operands are ill-formed.
29-
\end{note}
30-
\begin{example}
31-
\begin{codeblock}
32-
enum E1 { e };
33-
enum E2 { f };
34-
bool b = e <= 3.7; // deprecated
35-
int k = f - e; // deprecated
36-
auto cmp = e <=> f; // error
37-
\end{codeblock}
38-
\end{example}
39-
4019
\rSec1[depr.capture.this]{Implicit capture of \tcode{*this} by reference}
4120

4221
\pnum

source/xrefdelta.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
%
2020
% \removedxref{removed.label}
2121

22+
% P2864R2 Remove deprecated arithmetic conversions
23+
\removedxref{depr.arith.conv.enum}
24+
2225
% P2874R2 Mandating Annex D
2326
\removedxref{depr.res.on.required}
2427

0 commit comments

Comments
 (0)