Skip to content

Commit f3ec6d7

Browse files
authored
Merge 2024-11 CWG Motion 6
P2865R6 Remove Deprecated Array Comparisons from C++26
2 parents 9eb37be + 98e7eca commit f3ec6d7

File tree

4 files changed

+56
-33
lines changed

4 files changed

+56
-33
lines changed

source/compatibility.tex

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@
3333
\end{codeblock}
3434
\end{example}
3535

36+
\diffref{expr.rel,expr.eq}
37+
\change
38+
Comparing two objects of array type is no longer valid.
39+
\rationale
40+
The old behavior was confusing since it compared not the contents of the two
41+
arrays, but their addresses.
42+
\effect
43+
A valid \CppXXIII{} program directly comparing two array objects is rejected as
44+
ill-formed in this document.
45+
\begin{example}
46+
\begin{codeblock}
47+
int arr1[5];
48+
int arr2[5];
49+
bool same = arr1 == arr2; // ill-formed; previously well-formed
50+
bool idem = arr1 == +arr2; // compare addresses
51+
bool less = arr1 < +arr2; // compare addresses, unspecified result
52+
\end{codeblock}
53+
\end{example}
54+
3655
\diffref{expr.delete}
3756
\change
3857
Calling \tcode{delete} on a pointer to an incomplete class is ill-formed.
@@ -2925,6 +2944,30 @@
29252944
\howwide
29262945
Seldom.
29272946

2947+
\diffref{expr.rel,expr.eq}
2948+
\change
2949+
C allows directly comparing two objects of array type; \Cpp{} does not.
2950+
\rationale
2951+
The behavior is confusing because it compares not the contents of the two
2952+
arrays, but their addresses.
2953+
\effect
2954+
Deletion of semantically well-defined feature that had unspecified behavior
2955+
in common use cases.
2956+
\difficulty
2957+
Violations will be diagnosed by the \Cpp{} translator. The original behavior
2958+
can be replicated by explicitly casting either array to a pointer, such as by
2959+
using a unary \tcode{+}.
2960+
\begin{example}
2961+
\begin{codeblock}
2962+
int arr1[5];
2963+
int arr2[5];
2964+
int same = arr1 == arr2; // valid C, ill-formed C++
2965+
int idem = arr1 == +arr2; // valid in both C and C++
2966+
\end{codeblock}
2967+
\end{example}
2968+
\howwide
2969+
Rare.
2970+
29282971
\diffref{expr.cond,expr.ass,expr.comma}
29292972
\indextext{conversion!lvalue-to-rvalue}%
29302973
\indextext{rvalue!lvalue conversion to}%

source/expressions.tex

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6666,13 +6666,11 @@
66666666
\end{bnf}
66676667
%
66686668
The
6669-
lvalue-to-rvalue\iref{conv.lval},
6670-
array-to-pointer\iref{conv.array},
6669+
lvalue-to-rvalue\iref{conv.lval}
66716670
and function-to-pointer\iref{conv.func}
66726671
standard conversions are performed on the operands.
6673-
The comparison is deprecated if
6674-
both operands were of array type
6675-
prior to these conversions\iref{depr.array.comp}.
6672+
If one of the operands is a pointer, the
6673+
array-to-pointer conversion\iref{conv.array} is performed on the other operand.
66766674

66776675
\pnum
66786676
The converted operands shall have arithmetic, enumeration, or pointer type.
@@ -6684,7 +6682,7 @@
66846682

66856683
\pnum
66866684
The usual arithmetic conversions\iref{expr.arith.conv} are performed on operands of arithmetic
6687-
or enumeration type. If both operands are pointers,
6685+
or enumeration type. If both converted operands are pointers,
66886686
pointer conversions\iref{conv.ptr},
66896687
function pointer conversions\iref{conv.fctptr}, and
66906688
qualification conversions\iref{conv.qual}
@@ -6757,25 +6755,23 @@
67576755
The \tcode{==} (equal to) and the \tcode{!=} (not equal to) operators
67586756
group left-to-right.
67596757
The
6760-
lvalue-to-rvalue\iref{conv.lval},
6761-
array-to-pointer\iref{conv.array},
6758+
lvalue-to-rvalue\iref{conv.lval}
67626759
and function-to-pointer\iref{conv.func}
67636760
standard conversions are performed on the operands.
6764-
The comparison is deprecated if
6765-
both operands were of array type
6766-
prior to these conversions\iref{depr.array.comp}.
6761+
If one of the operands is a pointer or a null pointer constant\iref{conv.ptr},
6762+
the array-to-pointer conversion\iref{conv.array} is performed
6763+
on the other operand.
67676764

67686765
\pnum
6769-
The converted operands shall have arithmetic, enumeration, pointer,
6770-
or pointer-to-member type, or type \tcode{std::nullptr_t}. The operators
6766+
The converted operands shall have scalar type. The operators
67716767
\tcode{==} and \tcode{!=} both yield \keyword{true} or \keyword{false}, i.e., a
67726768
result of type \keyword{bool}. In each case below, the operands shall have the
67736769
same type after the specified conversions have been applied.
67746770

67756771
\pnum
67766772
\indextext{comparison!pointer}%
67776773
\indextext{comparison!pointer to function}%
6778-
If at least one of the operands is a pointer,
6774+
If at least one of the converted operands is a pointer,
67796775
pointer conversions\iref{conv.ptr},
67806776
function pointer conversions\iref{conv.fctptr}, and
67816777
qualification conversions\iref{conv.qual}

source/future.tex

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,6 @@
116116
\end{example}
117117

118118

119-
\rSec1[depr.array.comp]{Array comparisons}
120-
121-
\pnum
122-
Equality and relational comparisons\iref{expr.eq,expr.rel}
123-
between two operands of array type
124-
are deprecated.
125-
\begin{note}
126-
Three-way comparisons\iref{expr.spaceship} between such operands are ill-formed.
127-
\end{note}
128-
\begin{example}
129-
\begin{codeblock}
130-
int arr1[5];
131-
int arr2[5];
132-
bool same = arr1 == arr2; // deprecated, same as \tcode{\&arr1[0] == \&arr2[0]},
133-
// does not compare array contents
134-
auto cmp = arr1 <=> arr2; // error
135-
\end{codeblock}
136-
\end{example}
137-
138119
\rSec1[depr.impldec]{Implicit declaration of copy functions}
139120

140121
\pnum

source/xrefdelta.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
% P2864R2 Remove deprecated arithmetic conversions
2323
\removedxref{depr.arith.conv.enum}
2424

25+
% P2866R5 Remove deprecated array comparisons
26+
\removedxref{depr.array.comp}
27+
2528
% P2871R3 Remove deprecated <codecvt> header
2629
\removedxref{depr.codecvt.syn}
2730
\removedxref{depr.locale.stdcvt}

0 commit comments

Comments
 (0)