From Jason Turner

[diff.cpp20]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpb0_ka1g5/{from.md → to.md} +273 -0
tmp/tmpb0_ka1g5/{from.md → to.md} RENAMED
@@ -0,0 +1,273 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## C++ and ISO C++20 <a id="diff.cpp20">[[diff.cpp20]]</a>
2
+
3
+ ### General <a id="diff.cpp20.general">[[diff.cpp20.general]]</a>
4
+
5
+ Subclause [[diff.cpp20]] lists the differences between C++ and ISO C++20
6
+ (ISO/IEC 14882:2020, *Programming Languages — C++*), by the chapters of
7
+ this document.
8
+
9
+ ### [[lex]]: lexical conventions <a id="diff.cpp20.lex">[[diff.cpp20.lex]]</a>
10
+
11
+ **Change:** Previously valid identifiers containing characters not
12
+ present in UAX \#44 properties XID_Start or XID_Continue, or not in
13
+ Normalization Form C, are now rejected. **Rationale:** Prevent confusing
14
+ characters in identifiers. Requiring normalization of names ensures
15
+ consistent linker behavior. **Effect on original feature:** Some
16
+ identifiers are no longer well-formed.
17
+
18
+ **Change:** Concatenated *string-literal*s can no longer have
19
+ conflicting *encoding-prefix*es. **Rationale:** Removal of unimplemented
20
+ conditionally-supported feature. **Effect on original feature:**
21
+ Concatenation of *string-literal*s with different *encoding-prefix*es is
22
+ now ill-formed. For example:
23
+
24
+ ``` cpp
25
+ auto c = L"a" U"b"; // was conditionally-supported; now ill-formed
26
+ ```
27
+
28
+ ### [[expr]]: expressions <a id="diff.cpp20.expr">[[diff.cpp20.expr]]</a>
29
+
30
+ **Change:** Change move-eligible *id-expression*s from lvalues to
31
+ xvalues. **Rationale:** Simplify the rules for implicit move. **Effect
32
+ on original feature:** Valid C++20 code that relies on a returned
33
+ *id-expression*’s being an lvalue may change behavior or fail to
34
+ compile. For example:
35
+
36
+ ``` cpp
37
+ decltype(auto) f(int&& x) { return (x); } // returns int&&; previously returned int&
38
+ int& g(int&& x) { return x; } // ill-formed; previously well-formed
39
+ ```
40
+
41
+ **Change:** Change the meaning of comma in subscript expressions.
42
+ **Rationale:** Enable repurposing a deprecated syntax to support
43
+ multidimensional indexing. **Effect on original feature:** Valid C++20
44
+ code that uses a comma expression within a subscript expression may fail
45
+ to compile. For example:
46
+
47
+ ``` cpp
48
+ arr[1, 2] // was equivalent to arr[(1, 2)],
49
+ // now equivalent to arr.operator[](1, 2) or ill-formed
50
+ ```
51
+
52
+ ### [[stmt.stmt]]: statements <a id="diff.cpp20.stmt">[[diff.cpp20.stmt]]</a>
53
+
54
+ **Change:** The lifetime of temporary objects in the
55
+ *for-range-initializer* is extended until the end of the loop
56
+ [[class.temporary]]. **Rationale:** Improve usability of the range-based
57
+ `for` statement. **Effect on original feature:** Destructors of some
58
+ temporary objects are invoked later. For example:
59
+
60
+ ``` cpp
61
+ void f() {
62
+ std::vector<int> v = { 42, 17, 13 };
63
+ std::mutex m;
64
+
65
+ for (int x :
66
+ static_cast<void>(std::lock_guard<std::mutex>(m)), v) { // lock released in C++20
67
+ std::lock_guard<std::mutex> guard(m); // OK in C++20, now deadlocks
68
+ }
69
+ }
70
+ ```
71
+
72
+ ### [[dcl.dcl]]: declarations <a id="diff.cpp20.dcl">[[diff.cpp20.dcl]]</a>
73
+
74
+ **Change:** UTF-8 string literals may initialize arrays of `char` or
75
+ `unsigned char`. **Rationale:** Compatibility with previously written
76
+ code that conformed to previous versions of this document. **Effect on
77
+ original feature:** Arrays of `char` or `unsigned char` may now be
78
+ initialized with a UTF-8 string literal. This can affect initialization
79
+ that includes arrays that are directly initialized within class types,
80
+ typically aggregates. For example:
81
+
82
+ ``` cpp
83
+ struct A {
84
+ char8_t s[10];
85
+ };
86
+ struct B {
87
+ char s[10];
88
+ };
89
+
90
+ void f(A);
91
+ void f(B);
92
+
93
+ int main() {
94
+ f({u8""}); // ambiguous
95
+ }
96
+ ```
97
+
98
+ ### [[temp]]: templates <a id="diff.cpp20.temp">[[diff.cpp20.temp]]</a>
99
+
100
+ **Change:** Deducing template arguments from exception specifications.
101
+ **Rationale:** Facilitate generic handling of throwing and non-throwing
102
+ functions. **Effect on original feature:** Valid ISO C++20 code may be
103
+ ill-formed in this revision of C++. For example:
104
+
105
+ ``` cpp
106
+ template<bool> struct A { };
107
+ template<bool B> void f(void (*)(A<B>) noexcept(B));
108
+ void g(A<false>) noexcept;
109
+ void h() {
110
+ f(g); // ill-formed; previously well-formed
111
+ }
112
+ ```
113
+
114
+ ### [[library]]: library introduction <a id="diff.cpp20.library">[[diff.cpp20.library]]</a>
115
+
116
+ **Change:** New headers. **Rationale:** New functionality. **Effect on
117
+ original feature:** The following C++ headers are new: `<expected>`,
118
+ `<flat_map>`, `<flat_set>`, `<generator>`, `<print>`, `<spanstream>`,
119
+ `<stacktrace>`, and `<stdatomic.h>`. Valid C++20 code that `#include`s
120
+ headers with these names may be invalid in this revision of C++.
121
+
122
+ ### [[concepts]]: concepts library <a id="diff.cpp20.concepts">[[diff.cpp20.concepts]]</a>
123
+
124
+ **Change:** Replace `common_reference_with` in
125
+ `three_way_comparable_with`, `equality_comparable_with`, and
126
+ `totally_ordered_with` with an exposition-only concept. **Rationale:**
127
+ Allow uncopyable, but movable, types to model these concepts. **Effect
128
+ on original feature:** Valid C++20 code relying on subsumption with
129
+ `common_reference_with` may fail to compile in this revision of C++. For
130
+ example:
131
+
132
+ ``` cpp
133
+ template<class T, class U>
134
+ requires equality_comparable_with<T, U>
135
+ bool attempted_equals(const T&, const U& u); // previously selected overload
136
+
137
+ template<class T, class U>
138
+ requires common_reference_with<const remove_reference_t<T>&, const remove_reference_t<U>&>
139
+ bool attempted_equals(const T& t, const U& u); // ambiguous overload; previously
140
+ // rejected by partial ordering
141
+ bool test(shared_ptr<int> p) {
142
+ return attempted_equals(p, nullptr); // ill-formed; previously well-formed
143
+ }
144
+ ```
145
+
146
+ ### [[mem]]: memory management library <a id="diff.cpp20.memory">[[diff.cpp20.memory]]</a>
147
+
148
+ **Change:** Forbid partial and explicit program-defined specializations
149
+ of `allocator_traits`. **Rationale:** Allow addition of
150
+ `allocate_at_least` to `allocator_traits`, and potentially other members
151
+ in the future. **Effect on original feature:** Valid C++20 code that
152
+ partially or explicitly specializes `allocator_traits` is ill-formed
153
+ with no diagnostic required in this revision of C++.
154
+
155
+ ### [[utilities]]: general utilities library <a id="diff.cpp20.utilities">[[diff.cpp20.utilities]]</a>
156
+
157
+ **Change:** Signature changes: `format`, `format_to`, `vformat_to`,
158
+ `format_to_n`, `formatted_size`. Removal of `format_args_t`.
159
+ **Rationale:** Improve safety via compile-time format string checks,
160
+ avoid unnecessary template instantiations. **Effect on original
161
+ feature:** Valid C++20 code that contained errors in format strings or
162
+ relied on previous format string signatures or `format_args_t` may
163
+ become ill-formed. For example:
164
+
165
+ ``` cpp
166
+ auto s = std::format("{:d}", "I am not a number"); // ill-formed,
167
+ // previously threw format_error
168
+ ```
169
+
170
+ **Change:** Signature changes: `format`, `format_to`, `format_to_n`,
171
+ `formatted_size`. **Rationale:** Enable formatting of views that do not
172
+ support iteration when const-qualified and that are not copyable.
173
+ **Effect on original feature:** Valid C++20 code that passes bit fields
174
+ to formatting functions may become ill-formed. For example:
175
+
176
+ ``` cpp
177
+ struct tiny {
178
+ int bit: 1;
179
+ };
180
+
181
+ auto t = tiny();
182
+ std::format("{}", t.bit); // ill-formed, previously returned "0"
183
+ ```
184
+
185
+ **Change:** Restrict types of formatting arguments used as *width* or
186
+ *precision* in a *std-format-spec*. **Rationale:** Disallow types that
187
+ do not have useful or portable semantics as a formatting width or
188
+ precision. **Effect on original feature:** Valid C++20 code that passes
189
+ a boolean or character type as *arg-id* becomes invalid. For example:
190
+
191
+ ``` cpp
192
+ std::format("{:*^{}}", "", true); // ill-formed, previously returned "*"
193
+ std::format("{:*^{}}", "", '1'); // ill-formed, previously returned an
194
+ // implementation-defined number of '*' characters
195
+ ```
196
+
197
+ **Change:** Removed the `formatter` specialization:
198
+
199
+ ``` cpp
200
+ template<size_t N> struct formatter<const charT[N], charT>;
201
+ ```
202
+
203
+ **Rationale:** The specialization is inconsistent with the design of
204
+ `formatter`, which is intended to be instantiated only with
205
+ cv-unqualified object types. **Effect on original feature:** Valid C++20
206
+ code that instantiated the removed specialization can become ill-formed.
207
+
208
+ ### [[strings]]: strings library <a id="diff.cpp20.strings">[[diff.cpp20.strings]]</a>
209
+
210
+ **Change:** Additional rvalue overload for the `substr` member function
211
+ and the corresponding constructor. **Rationale:** Improve efficiency of
212
+ operations on rvalues. **Effect on original feature:** Valid C++20 code
213
+ that created a substring by calling `substr` (or the corresponding
214
+ constructor) on an xvalue expression with type `S` that is a
215
+ specialization of `basic_string` may change meaning in this revision of
216
+ C++. For example:
217
+
218
+ ``` cpp
219
+ std::string s1 = "some long string that forces allocation", s2 = s1;
220
+ std::move(s1).substr(10, 5);
221
+ assert(s1 == s2); // unspecified, previously guaranteed to be true
222
+ std::string s3(std::move(s2), 10, 5);
223
+ assert(s1 == s2); // unspecified, previously guaranteed to be true
224
+ ```
225
+
226
+ ### [[containers]]: containers library <a id="diff.cpp20.containers">[[diff.cpp20.containers]]</a>
227
+
228
+ **Change:** Heterogeneous `extract` and `erase` overloads for
229
+ associative containers. **Rationale:** Improve efficiency of erasing
230
+ elements from associative containers. **Effect on original feature:**
231
+ Valid C++20 code may fail to compile in this revision of C++. For
232
+ example:
233
+
234
+ ``` cpp
235
+ struct B {
236
+ auto operator<=>(const B&) const = default;
237
+ };
238
+
239
+ struct D : private B {
240
+ void f(std::set<B, std::less<>>& s) {
241
+ s.erase(*this); // ill formed; previously well-formed
242
+ }
243
+ };
244
+ ```
245
+
246
+ ### [[thread]]: concurrency support library <a id="diff.cpp20.thread">[[diff.cpp20.thread]]</a>
247
+
248
+ **Change:** In this revision of C++, it is implementation-defined
249
+ whether a barrier’s phase completion step runs if no thread calls
250
+ `wait`. Previously the phase completion step was guaranteed to run on
251
+ the last thread that calls `arrive` or `arrive_and_drop` during the
252
+ phase. In this revision of C++, it can run on any of the threads that
253
+ arrived or waited at the barrier during the phase. **Rationale:**
254
+ Correct contradictory wording and improve implementation flexibility for
255
+ performance. **Effect on original feature:** Valid C++20 code using a
256
+ barrier might have different semantics in this revision of C++ if it
257
+ depends on a completion function’s side effects occurring exactly once,
258
+ on a specific thread running the phase completion step, or on a
259
+ completion function’s side effects occurring without `wait` having been
260
+ called. For example:
261
+
262
+ ``` cpp
263
+ auto b0 = std::barrier(1);
264
+ b0.arrive();
265
+ b0.arrive(); // implementation-defined; previously well-defined
266
+
267
+ int data = 0;
268
+ auto b1 = std::barrier(1, [&] { data++; });
269
+ b1.arrive();
270
+ assert(data == 1); // implementation-defined; previously well-defined
271
+ b1.arrive(); // implementation-defined; previously well-defined
272
+ ```
273
+