Skip to content

Commit

Permalink
P2865R6 Remove Deprecated Array Comparisons from C++26
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisdairM committed Dec 3, 2024
1 parent aed9756 commit 8d85129
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 33 deletions.
43 changes: 43 additions & 0 deletions source/compatibility.tex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@
\end{codeblock}
\end{example}

\diffref{expr.rel,expr.eq}
\change
Comparing two objects of array type is no longer valid.
\rationale
The old behavior was confusing since it compared not the contents of the two
arrays, but their addresses.
\effect
A valid \CppXXIII{} program directly comparing two array objects is rejected as
ill-formed in this document.
\begin{example}
\begin{codeblock}
int arr1[5];
int arr2[5];
bool same = arr1 == arr2; // ill-formed; previously well-formed
bool idem = arr1 == +arr2; // compare addresses
bool less = arr1 < +arr2; // compare addresses, unspecified result
\end{codeblock}
\end{example}

\diffref{expr.delete}
\change
Calling \tcode{delete} on a pointer to an incomplete class is ill-formed.
Expand Down Expand Up @@ -2893,6 +2912,30 @@
\howwide
Seldom.

\diffref{expr.rel,expr.eq}
\change
C allows directly comparing two objects of array type; \Cpp{} does not.
\rationale
The behavior is confusing because it compares not the contents of the two
arrays, but their addresses.
\effect
Deletion of semantically well-defined feature that had unspecified behavior
in common use cases.
\difficulty
Violations will be diagnosed by the \Cpp{} translator. The original behavior
can be replicated by explicitly casting either array to a pointer, such as by
using a unary \tcode{+}.
\begin{example}
\begin{codeblock}
int arr1[5];
int arr2[5];
int same = arr1 == arr2; // valid C, ill-formed C++
int idem = arr1 == +arr2; // valid in both C and C++
\end{codeblock}
\end{example}
\howwide
Rare.

\diffref{expr.cond,expr.ass,expr.comma}
\indextext{conversion!lvalue-to-rvalue}%
\indextext{rvalue!lvalue conversion to}%
Expand Down
24 changes: 10 additions & 14 deletions source/expressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -6626,13 +6626,11 @@
\end{bnf}
%
The
lvalue-to-rvalue\iref{conv.lval},
array-to-pointer\iref{conv.array},
lvalue-to-rvalue\iref{conv.lval}
and function-to-pointer\iref{conv.func}
standard conversions are performed on the operands.
The comparison is deprecated if
both operands were of array type
prior to these conversions\iref{depr.array.comp}.
If one of the operands is a pointer, the
array-to-pointer conversion\iref{conv.array} is performed on the other operand.

\pnum
The converted operands shall have arithmetic, enumeration, or pointer type.
Expand All @@ -6644,7 +6642,7 @@

\pnum
The usual arithmetic conversions\iref{expr.arith.conv} are performed on operands of arithmetic
or enumeration type. If both operands are pointers,
or enumeration type. If both converted operands are pointers,
pointer conversions\iref{conv.ptr},
function pointer conversions\iref{conv.fctptr}, and
qualification conversions\iref{conv.qual}
Expand Down Expand Up @@ -6717,25 +6715,23 @@
The \tcode{==} (equal to) and the \tcode{!=} (not equal to) operators
group left-to-right.
The
lvalue-to-rvalue\iref{conv.lval},
array-to-pointer\iref{conv.array},
lvalue-to-rvalue\iref{conv.lval}
and function-to-pointer\iref{conv.func}
standard conversions are performed on the operands.
The comparison is deprecated if
both operands were of array type
prior to these conversions\iref{depr.array.comp}.
If one of the operands is a pointer or a null pointer constant\iref{conv.ptr},
the array-to-pointer conversion\iref{conv.array} is performed
on the other operand.

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

\pnum
\indextext{comparison!pointer}%
\indextext{comparison!pointer to function}%
If at least one of the operands is a pointer,
If at least one of the converted operands is a pointer,
pointer conversions\iref{conv.ptr},
function pointer conversions\iref{conv.fctptr}, and
qualification conversions\iref{conv.qual}
Expand Down
19 changes: 0 additions & 19 deletions source/future.tex
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,6 @@
\end{example}


\rSec1[depr.array.comp]{Array comparisons}

\pnum
Equality and relational comparisons\iref{expr.eq,expr.rel}
between two operands of array type
are deprecated.
\begin{note}
Three-way comparisons\iref{expr.spaceship} between such operands are ill-formed.
\end{note}
\begin{example}
\begin{codeblock}
int arr1[5];
int arr2[5];
bool same = arr1 == arr2; // deprecated, same as \tcode{\&arr1[0] == \&arr2[0]},
// does not compare array contents
auto cmp = arr1 <=> arr2; // error
\end{codeblock}
\end{example}

\rSec1[depr.impldec]{Implicit declaration of copy functions}

\pnum
Expand Down
3 changes: 3 additions & 0 deletions source/xrefdelta.tex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
% P2864R2 Remove deprecated arithmetic conversions
\removedxref{depr.arith.conv.enum}

% P2866R5 Remove deprecated array comparisons
\removedxref{depr.array.comp}

% P2871R3 Remove deprecated <codecvt> header
\removedxref{depr.codecvt.syn}
\removedxref{depr.locale.stdcvt}
Expand Down

0 comments on commit 8d85129

Please sign in to comment.