From Jason Turner

[diff.cpp20]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpxd80fxyc/{from.md → to.md} +76 -25
tmp/tmpxd80fxyc/{from.md → to.md} RENAMED
@@ -1,12 +1,12 @@
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
@@ -17,47 +17,61 @@ 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;
@@ -67,19 +81,23 @@ void f() {
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
  };
@@ -93,43 +111,51 @@ void f(B);
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
@@ -141,10 +167,12 @@ bool attempted_equals(const T& t, const U& u); // ambiguous overload; previousl
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
@@ -158,44 +186,56 @@ with no diagnostic required in this revision of C++.
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
  ```
@@ -211,40 +251,47 @@ code that instantiated the removed specialization can become ill-formed.
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
@@ -255,11 +302,13 @@ 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
@@ -269,5 +318,7 @@ 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
 
 
 
 
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
6
+ C++20, in addition to those listed above, by the chapters of this
7
+ 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
 
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.
23
+
24
+ [*Example 1*:
25
 
26
  ``` cpp
27
  auto c = L"a" U"b"; // was conditionally-supported; now ill-formed
28
  ```
29
 
30
+ — *end example*]
31
+
32
  ### [[expr]]: expressions <a id="diff.cpp20.expr">[[diff.cpp20.expr]]</a>
33
 
34
  **Change:** Change move-eligible *id-expression*s from lvalues to
35
  xvalues. **Rationale:** Simplify the rules for implicit move. **Effect
36
  on original feature:** Valid C++20 code that relies on a returned
37
  *id-expression*’s being an lvalue may change behavior or fail to
38
+ compile.
39
+
40
+ [*Example 1*:
41
 
42
  ``` cpp
43
  decltype(auto) f(int&& x) { return (x); } // returns int&&; previously returned int&
44
  int& g(int&& x) { return x; } // ill-formed; previously well-formed
45
  ```
46
 
47
+ — *end example*]
48
+
49
  **Change:** Change the meaning of comma in subscript expressions.
50
  **Rationale:** Enable repurposing a deprecated syntax to support
51
  multidimensional indexing. **Effect on original feature:** Valid C++20
52
  code that uses a comma expression within a subscript expression may fail
53
+ to compile.
54
+
55
+ [*Example 2*:
56
 
57
  ``` cpp
58
  arr[1, 2] // was equivalent to arr[(1, 2)],
59
  // now equivalent to arr.operator[](1, 2) or ill-formed
60
  ```
61
 
62
+ *end example*]
63
+
64
+ ### [[stmt]]: statements <a id="diff.cpp20.stmt">[[diff.cpp20.stmt]]</a>
65
 
66
  **Change:** The lifetime of temporary objects in the
67
  *for-range-initializer* is extended until the end of the loop
68
  [[class.temporary]]. **Rationale:** Improve usability of the range-based
69
  `for` statement. **Effect on original feature:** Destructors of some
70
+ temporary objects are invoked later.
71
+
72
+ [*Example 1*:
73
 
74
  ``` cpp
75
  void f() {
76
  std::vector<int> v = { 42, 17, 13 };
77
  std::mutex m;
 
81
  std::lock_guard<std::mutex> guard(m); // OK in C++20, now deadlocks
82
  }
83
  }
84
  ```
85
 
86
+ *end example*]
87
+
88
+ ### [[dcl]]: declarations <a id="diff.cpp20.dcl">[[diff.cpp20.dcl]]</a>
89
 
90
  **Change:** UTF-8 string literals may initialize arrays of `char` or
91
  `unsigned char`. **Rationale:** Compatibility with previously written
92
  code that conformed to previous versions of this document. **Effect on
93
  original feature:** Arrays of `char` or `unsigned char` may now be
94
  initialized with a UTF-8 string literal. This can affect initialization
95
  that includes arrays that are directly initialized within class types,
96
+ typically aggregates.
97
+
98
+ [*Example 1*:
99
 
100
  ``` cpp
101
  struct A {
102
  char8_t s[10];
103
  };
 
111
  int main() {
112
  f({u8""}); // ambiguous
113
  }
114
  ```
115
 
116
+ — *end example*]
117
+
118
  ### [[temp]]: templates <a id="diff.cpp20.temp">[[diff.cpp20.temp]]</a>
119
 
120
  **Change:** Deducing template arguments from exception specifications.
121
  **Rationale:** Facilitate generic handling of throwing and non-throwing
122
  functions. **Effect on original feature:** Valid ISO C++20 code may be
123
+ ill-formed in this revision of C++.
124
+
125
+ [*Example 1*:
126
 
127
  ``` cpp
128
  template<bool> struct A { };
129
  template<bool B> void f(void (*)(A<B>) noexcept(B));
130
  void g(A<false>) noexcept;
131
  void h() {
132
  f(g); // ill-formed; previously well-formed
133
  }
134
  ```
135
 
136
+ — *end example*]
137
+
138
  ### [[library]]: library introduction <a id="diff.cpp20.library">[[diff.cpp20.library]]</a>
139
 
140
  **Change:** New headers. **Rationale:** New functionality. **Effect on
141
  original feature:** The following C++ headers are new: `<expected>`,
142
+ `<flat_map>`, `<flat_set>`, `<generator>`, `<mdspan>`, `<print>`,
143
+ `<spanstream>`, `<stacktrace>`, `<stdatomic.h>`, and `<stdfloat>`. Valid
144
+ C++20 code that `#include`s headers with these names may be invalid in
145
+ this revision of C++.
146
 
147
  ### [[concepts]]: concepts library <a id="diff.cpp20.concepts">[[diff.cpp20.concepts]]</a>
148
 
149
  **Change:** Replace `common_reference_with` in
150
  `three_way_comparable_with`, `equality_comparable_with`, and
151
  `totally_ordered_with` with an exposition-only concept. **Rationale:**
152
  Allow uncopyable, but movable, types to model these concepts. **Effect
153
  on original feature:** Valid C++20 code relying on subsumption with
154
+ `common_reference_with` may fail to compile in this revision of C++.
155
+
156
+ [*Example 1*:
157
 
158
  ``` cpp
159
  template<class T, class U>
160
  requires equality_comparable_with<T, U>
161
  bool attempted_equals(const T&, const U& u); // previously selected overload
 
167
  bool test(shared_ptr<int> p) {
168
  return attempted_equals(p, nullptr); // ill-formed; previously well-formed
169
  }
170
  ```
171
 
172
+ — *end example*]
173
+
174
  ### [[mem]]: memory management library <a id="diff.cpp20.memory">[[diff.cpp20.memory]]</a>
175
 
176
  **Change:** Forbid partial and explicit program-defined specializations
177
  of `allocator_traits`. **Rationale:** Allow addition of
178
  `allocate_at_least` to `allocator_traits`, and potentially other members
 
186
  `format_to_n`, `formatted_size`. Removal of `format_args_t`.
187
  **Rationale:** Improve safety via compile-time format string checks,
188
  avoid unnecessary template instantiations. **Effect on original
189
  feature:** Valid C++20 code that contained errors in format strings or
190
  relied on previous format string signatures or `format_args_t` may
191
+ become ill-formed.
192
+
193
+ [*Example 1*:
194
 
195
  ``` cpp
196
  auto s = std::format("{:d}", "I am not a number"); // ill-formed,
197
  // previously threw format_error
198
  ```
199
 
200
+ — *end example*]
201
+
202
  **Change:** Signature changes: `format`, `format_to`, `format_to_n`,
203
  `formatted_size`. **Rationale:** Enable formatting of views that do not
204
  support iteration when const-qualified and that are not copyable.
205
+ **Effect on original feature:** Valid C++20 code that passes bit-fields
206
+ to formatting functions may become ill-formed.
207
+
208
+ [*Example 2*:
209
 
210
  ``` cpp
211
  struct tiny {
212
  int bit: 1;
213
  };
214
 
215
  auto t = tiny();
216
  std::format("{}", t.bit); // ill-formed, previously returned "0"
217
  ```
218
 
219
+ — *end example*]
220
+
221
  **Change:** Restrict types of formatting arguments used as *width* or
222
  *precision* in a *std-format-spec*. **Rationale:** Disallow types that
223
  do not have useful or portable semantics as a formatting width or
224
  precision. **Effect on original feature:** Valid C++20 code that passes
225
+ a boolean or character type as *arg-id* becomes invalid.
226
+
227
+ [*Example 3*:
228
 
229
  ``` cpp
230
  std::format("{:*^{}}", "", true); // ill-formed, previously returned "*"
231
  std::format("{:*^{}}", "", '1'); // ill-formed, previously returned an
232
  // implementation-defined number of '*' characters
233
  ```
234
 
235
+ — *end example*]
236
+
237
  **Change:** Removed the `formatter` specialization:
238
 
239
  ``` cpp
240
  template<size_t N> struct formatter<const charT[N], charT>;
241
  ```
 
251
  and the corresponding constructor. **Rationale:** Improve efficiency of
252
  operations on rvalues. **Effect on original feature:** Valid C++20 code
253
  that created a substring by calling `substr` (or the corresponding
254
  constructor) on an xvalue expression with type `S` that is a
255
  specialization of `basic_string` may change meaning in this revision of
256
+ C++.
257
+
258
+ [*Example 1*:
259
 
260
  ``` cpp
261
  std::string s1 = "some long string that forces allocation", s2 = s1;
262
  std::move(s1).substr(10, 5);
263
  assert(s1 == s2); // unspecified, previously guaranteed to be true
264
  std::string s3(std::move(s2), 10, 5);
265
  assert(s1 == s2); // unspecified, previously guaranteed to be true
266
  ```
267
 
268
+ — *end example*]
269
+
270
  ### [[containers]]: containers library <a id="diff.cpp20.containers">[[diff.cpp20.containers]]</a>
271
 
272
  **Change:** Heterogeneous `extract` and `erase` overloads for
273
  associative containers. **Rationale:** Improve efficiency of erasing
274
  elements from associative containers. **Effect on original feature:**
275
+ Valid C++20 code may fail to compile in this revision of C++.
276
+
277
+ [*Example 1*:
278
 
279
  ``` cpp
280
  struct B {
281
  auto operator<=>(const B&) const = default;
282
  };
283
 
284
  struct D : private B {
285
  void f(std::set<B, std::less<>>& s) {
286
+ s.erase(*this); // ill-formed; previously well-formed
287
  }
288
  };
289
  ```
290
 
291
+ — *end example*]
292
+
293
  ### [[thread]]: concurrency support library <a id="diff.cpp20.thread">[[diff.cpp20.thread]]</a>
294
 
295
  **Change:** In this revision of C++, it is implementation-defined
296
  whether a barrier’s phase completion step runs if no thread calls
297
  `wait`. Previously the phase completion step was guaranteed to run on
 
302
  performance. **Effect on original feature:** Valid C++20 code using a
303
  barrier might have different semantics in this revision of C++ if it
304
  depends on a completion function’s side effects occurring exactly once,
305
  on a specific thread running the phase completion step, or on a
306
  completion function’s side effects occurring without `wait` having been
307
+ called.
308
+
309
+ [*Example 1*:
310
 
311
  ``` cpp
312
  auto b0 = std::barrier(1);
313
  b0.arrive();
314
  b0.arrive(); // implementation-defined; previously well-defined
 
318
  b1.arrive();
319
  assert(data == 1); // implementation-defined; previously well-defined
320
  b1.arrive(); // implementation-defined; previously well-defined
321
  ```
322
 
323
+ — *end example*]
324
+