Skip to content

Commit fd244b5

Browse files
committed
[diff.cpp03.language.support] Remove change described in p1, which is no
longer a possible change. It is not possible to write a global replacement operator new or operator delete in C++20 with code that is also valid C++03, because a) operator new must be declared 'throw(std::bad_alloc)' in C++03 and must be declared with no exception specification in C++11 onwards, and b) operator delete must be declared 'throw()' in C++03 and must be declared 'noexcept' in C++20 onwards. Therefore there is no code that is valid in C++03 and C++20 and changes meaning due to the change identified in this section. Instead, expand [diff.cpp03.language.support]p2 to explain that the affected programs are simply not valid in C++20.
1 parent 3e80cd4 commit fd244b5

File tree

1 file changed

+4
-34
lines changed

1 file changed

+4
-34
lines changed

source/compatibility.tex

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,40 +1119,6 @@
11191119
\rSec2[diff.cpp03.language.support]{\ref{language.support}:
11201120
language support library}
11211121

1122-
\diffref{new.delete.single}
1123-
\change Linking \tcode{new} and \tcode{delete} operators.
1124-
\rationale The two throwing single-object signatures of \tcode{operator new} and
1125-
\tcode{operator delete} are now specified to form the base functionality for
1126-
the other operators. This clarifies that replacing just these two signatures
1127-
changes others, even if they are not explicitly changed.
1128-
\effect
1129-
Valid \CppIII{} code that replaces global \tcode{new} or \tcode{delete}
1130-
operators may execute differently in this International Standard. For
1131-
example, the following program should write \tcode{"custom deallocation"} twice,
1132-
once for the single-object delete and once for the array delete.
1133-
1134-
\begin{codeblock}
1135-
#include <cstdio>
1136-
#include <cstdlib>
1137-
#include <new>
1138-
1139-
void* operator new(std::size_t size) throw(std::bad_alloc) {
1140-
return std::malloc(size);
1141-
}
1142-
1143-
void operator delete(void* ptr) throw() {
1144-
std::puts("custom deallocation");
1145-
std::free(ptr);
1146-
}
1147-
1148-
int main() {
1149-
int* i = new int;
1150-
delete i; // single-object delete
1151-
int* a = new int[3];
1152-
delete [] a; // array delete
1153-
}
1154-
\end{codeblock}
1155-
11561122
\diffref{new.delete.single}
11571123
\change \tcode{operator new} may throw exceptions other than
11581124
\tcode{std::bad_alloc}.
@@ -1161,6 +1127,10 @@
11611127
Valid \CppIII{} code that assumes that global \tcode{operator new} only
11621128
throws \tcode{std::bad_alloc} may execute differently in this International
11631129
Standard.
1130+
Valid \CppIII{} code that replaces the global replaceable \tcode{operator new}
1131+
is ill-formed in this International Standard,
1132+
because the exception specification of \tcode{throw(std::bad_alloc)}
1133+
was removed.
11641134

11651135
\rSec2[diff.cpp03.diagnostics]{\ref{diagnostics}: diagnostics library}
11661136

0 commit comments

Comments
 (0)