From Jason Turner

[diff.cpp03]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmphx00aid4/{from.md → to.md} +119 -32
tmp/tmphx00aid4/{from.md → to.md} RENAMED
@@ -1,31 +1,36 @@
1
  ## C++ and ISO C++03 <a id="diff.cpp03">[[diff.cpp03]]</a>
2
 
3
  ### General <a id="diff.cpp03.general">[[diff.cpp03.general]]</a>
4
 
5
- Subclause [[diff.cpp03]] lists the differences between C++ and ISO C++03
6
- (ISO/IEC 14882:2003, *Programming Languages — C++*), in addition to
7
- those listed above, by the chapters of this document.
8
 
9
  ### [[lex]]: lexical conventions <a id="diff.cpp03.lex">[[diff.cpp03.lex]]</a>
10
 
11
  **Change:** New kinds of *string-literal*s. **Rationale:** Required for
12
  new features. **Effect on original feature:** Valid C++03 code may fail
13
  to compile or produce different results in this revision of C++.
14
  Specifically, macros named `R`, `u8`, `u8R`, `u`, `uR`, `U`, `UR`, or
15
  `LR` will not be expanded when adjacent to a *string-literal* but will
16
- be interpreted as part of the *string-literal*. For example:
 
 
17
 
18
  ``` cpp
19
  #define u8 "abc"
20
  const char* s = u8"def"; // Previously "abcdef", now "def"
21
  ```
22
 
 
 
23
  **Change:** User-defined literal string support. **Rationale:** Required
24
  for new features. **Effect on original feature:** Valid C++03 code may
25
  fail to compile or produce different results in this revision of C++.
26
- For example:
 
27
 
28
  ``` cpp
29
  #define _x "there"
30
  "hello"_x // #1
31
  ```
@@ -33,10 +38,12 @@ For example:
33
  Previously, \#1 would have consisted of two separate preprocessing
34
  tokens and the macro `_x` would have been expanded. In this revision of
35
  C++, \#1 consists of a single preprocessing token, so the macro is not
36
  expanded.
37
 
 
 
38
  **Change:** New keywords. **Rationale:** Required for new features.
39
  **Effect on original feature:** Added to [[lex.key]], the following
40
  identifiers are new keywords: `alignas`, `alignof`, `char16_t`,
41
  `char32_t`, `constexpr`, `decltype`, `noexcept`, `nullptr`,
42
  `static_assert`, and `thread_local`. Valid C++03 code using these
@@ -51,56 +58,133 @@ be represented by `long` could change from an unsigned integer type to
51
 
52
  **Change:** Only literals are integer null pointer constants.
53
  **Rationale:** Removing surprising interactions with templates and
54
  constant expressions. **Effect on original feature:** Valid C++03 code
55
  may fail to compile or produce different results in this revision of
56
- C++. For example:
 
 
57
 
58
  ``` cpp
59
  void f(void *); // #1
60
  void f(...); // #2
61
  template<int N> void g() {
62
  f(0*N); // calls #2; used to call #1
63
  }
64
  ```
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  **Change:** Specify rounding for results of integer `/` and `%`.
67
  **Rationale:** Increase portability, C99 compatibility. **Effect on
68
  original feature:** Valid C++03 code that uses integer division rounds
69
  the result toward 0 or toward negative infinity, whereas this revision
70
  of C++ always rounds the result toward 0.
71
 
72
  **Change:** `&&` is valid in a *type-name*. **Rationale:** Required for
73
  new features. **Effect on original feature:** Valid C++03 code may fail
74
- to compile or produce different results in this revision of C++. For
75
- example:
 
76
 
77
  ``` cpp
78
  bool b1 = new int && false; // previously false, now ill-formed
79
  struct S { operator int(); };
80
  bool b2 = &S::operator int && false; // previously false, now ill-formed
81
  ```
82
 
83
- ### [[dcl.dcl]]: declarations <a id="diff.cpp03.dcl.dcl">[[diff.cpp03.dcl.dcl]]</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  **Change:** Remove `auto` as a storage class specifier. **Rationale:**
86
  New feature. **Effect on original feature:** Valid C++03 code that uses
87
  the keyword `auto` as a storage class specifier may be invalid in this
88
  revision of C++. In this revision of C++, `auto` indicates that the type
89
  of a variable is to be deduced from its initializer expression.
90
 
91
  **Change:** Narrowing restrictions in aggregate initializers.
92
  **Rationale:** Catches bugs. **Effect on original feature:** Valid C++03
93
- code may fail to compile in this revision of C++. For example:
 
 
94
 
95
  ``` cpp
96
  int x[] = { 2.0 };
97
  ```
98
 
99
  This code is valid in C++03 but invalid in this revision of C++ because
100
  `double` to `int` is a narrowing conversion.
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  ### [[class]]: classes <a id="diff.cpp03.class">[[diff.cpp03.class]]</a>
103
 
104
  **Change:** Implicitly-declared special member functions are defined as
105
  deleted when the implicit definition would have been ill-formed.
106
  **Rationale:** Improves template argument deduction failure. **Effect on
@@ -128,65 +212,65 @@ ill-formed in this revision of C++.
128
  right angle brackets. **Rationale:** Considered a persistent but minor
129
  annoyance. Template aliases representing non-class types would
130
  exacerbate whitespace issues. **Effect on original feature:** Change to
131
  semantics of well-defined expression. A valid C++03 expression
132
  containing a right angle bracket (“`>`”) followed immediately by another
133
- right angle bracket may now be treated as closing two templates. For
134
- example:
 
135
 
136
  ``` cpp
137
  template <class T> struct X { };
138
  template <int N> struct Y { };
139
  X< Y< 1 >> 2 > > x;
140
  ```
141
 
142
  This code is valid in C++03 because “`>>`” is a right-shift operator,
143
  but invalid in this revision of C++ because “`>>`” closes two templates.
144
 
 
 
145
  **Change:** Allow dependent calls of functions with internal linkage.
146
  **Rationale:** Overly constrained, simplify overload resolution rules.
147
  **Effect on original feature:** A valid C++03 program can get a
148
  different result in this revision of C++.
149
 
150
  ### [[library]]: library introduction <a id="diff.cpp03.library">[[diff.cpp03.library]]</a>
151
 
152
- **Affected:** [[library]] – [[thread]] **Change:** New reserved
153
  identifiers. **Rationale:** Required by new features. **Effect on
154
  original feature:** Valid C++03 code that uses any identifiers added to
155
  the C++ standard library by later revisions of C++ may fail to compile
156
  or produce different results in this revision of C++. A comprehensive
157
  list of identifiers used by the C++ standard library can be found in the
158
  Index of Library Names in this document.
159
 
160
  **Change:** New headers. **Rationale:** New functionality. **Effect on
161
  original feature:** The following C++ headers are new: `<array>`,
162
- `<atomic>`, `<chrono>`, , `<condition_variable>`, `<forward_list>`,
163
- `<future>`, `<initializer_list>`, `<mutex>`, `<random>`, `<ratio>`,
164
- `<regex>`, `<scoped_allocator>`, `<system_error>`, `<thread>`,
165
- `<tuple>`, `<typeindex>`, `<type_traits>`, `<unordered_map>`, and
166
- `<unordered_set>`. In addition the following C compatibility headers are
167
- new: `<cfenv>`, `<cinttypes>`, `<cstdint>`, and `<cuchar>`. Valid C++03
168
- code that `#include`s headers with these names may be invalid in this
169
- revision of C++.
170
 
171
- **Effect on original feature:** Function `swap` moved to a different
172
- header **Rationale:** Remove dependency on `<algorithm>` for `swap`.
173
- **Effect on original feature:** Valid C++03 code that has been compiled
174
- expecting swap to be in `<algorithm>` may have to instead include
175
- `<utility>`.
176
 
177
  **Change:** New reserved namespace. **Rationale:** New functionality.
178
  **Effect on original feature:** The global namespace `posix` is now
179
  reserved for standardization. Valid C++03 code that uses a top-level
180
  namespace `posix` may be invalid in this revision of C++.
181
 
182
  **Change:** Additional restrictions on macro names. **Rationale:** Avoid
183
  hard to diagnose or non-portable constructs. **Effect on original
184
  feature:** Names of attribute identifiers may not be used as macro
185
- names. Valid C++03 code that defines `override`, `final`,
186
- `carries_dependency`, or `noreturn` as macros is invalid in this
187
- revision of C++.
188
 
189
  ### [[support]]: language support library <a id="diff.cpp03.language.support">[[diff.cpp03.language.support]]</a>
190
 
191
  **Change:** `operator new` may throw exceptions other than
192
  `std::bad_alloc`. **Rationale:** Consistent application of `noexcept`.
@@ -309,11 +393,11 @@ that uses implementation-specific knowledge about the binary
309
  representation of the required template specializations of
310
  `std::complex` may not be compatible with this revision of C++.
311
 
312
  ### [[localization]]: localization library <a id="diff.cpp03.locale">[[diff.cpp03.locale]]</a>
313
 
314
- **Change:** The `num_get` facet recognizes hexadecimal floating point
315
  values. **Rationale:** Required by new feature. **Effect on original
316
  feature:** Valid C++03 code may have different behavior in this revision
317
  of C++.
318
 
319
  ### [[input.output]]: input/output library <a id="diff.cpp03.input.output">[[diff.cpp03.input.output]]</a>
@@ -340,17 +424,20 @@ may execute differently in this revision of C++.
340
 
341
  **Change:** Flag types in `std::ios_base` are now bitmasks with values
342
  defined as constexpr static members. **Rationale:** Required for new
343
  features. **Effect on original feature:** Valid C++03 code that relies
344
  on `std::ios_base` flag types being represented as `std::bitset` or as
345
- an integer type may fail to compile with this revision of C++. For
346
- example:
 
347
 
348
  ``` cpp
349
  #include <iostream>
350
 
351
  int main() {
352
  int flag = std::ios_base::hex;
353
  std::cout.setf(flag); // error: setf does not take argument of type int
354
  }
355
  ```
356
 
 
 
 
1
  ## C++ and ISO C++03 <a id="diff.cpp03">[[diff.cpp03]]</a>
2
 
3
  ### General <a id="diff.cpp03.general">[[diff.cpp03.general]]</a>
4
 
5
+ Subclause [[diff.cpp03]] lists the differences between C++ and ISO
6
+ C++03, in addition to those listed above, by the chapters of this
7
+ document.
8
 
9
  ### [[lex]]: lexical conventions <a id="diff.cpp03.lex">[[diff.cpp03.lex]]</a>
10
 
11
  **Change:** New kinds of *string-literal*s. **Rationale:** Required for
12
  new features. **Effect on original feature:** Valid C++03 code may fail
13
  to compile or produce different results in this revision of C++.
14
  Specifically, macros named `R`, `u8`, `u8R`, `u`, `uR`, `U`, `UR`, or
15
  `LR` will not be expanded when adjacent to a *string-literal* but will
16
+ be interpreted as part of the *string-literal*.
17
+
18
+ [*Example 1*:
19
 
20
  ``` cpp
21
  #define u8 "abc"
22
  const char* s = u8"def"; // Previously "abcdef", now "def"
23
  ```
24
 
25
+ — *end example*]
26
+
27
  **Change:** User-defined literal string support. **Rationale:** Required
28
  for new features. **Effect on original feature:** Valid C++03 code may
29
  fail to compile or produce different results in this revision of C++.
30
+
31
+ [*Example 2*:
32
 
33
  ``` cpp
34
  #define _x "there"
35
  "hello"_x // #1
36
  ```
 
38
  Previously, \#1 would have consisted of two separate preprocessing
39
  tokens and the macro `_x` would have been expanded. In this revision of
40
  C++, \#1 consists of a single preprocessing token, so the macro is not
41
  expanded.
42
 
43
+ — *end example*]
44
+
45
  **Change:** New keywords. **Rationale:** Required for new features.
46
  **Effect on original feature:** Added to [[lex.key]], the following
47
  identifiers are new keywords: `alignas`, `alignof`, `char16_t`,
48
  `char32_t`, `constexpr`, `decltype`, `noexcept`, `nullptr`,
49
  `static_assert`, and `thread_local`. Valid C++03 code using these
 
58
 
59
  **Change:** Only literals are integer null pointer constants.
60
  **Rationale:** Removing surprising interactions with templates and
61
  constant expressions. **Effect on original feature:** Valid C++03 code
62
  may fail to compile or produce different results in this revision of
63
+ C++.
64
+
65
+ [*Example 1*:
66
 
67
  ``` cpp
68
  void f(void *); // #1
69
  void f(...); // #2
70
  template<int N> void g() {
71
  f(0*N); // calls #2; used to call #1
72
  }
73
  ```
74
 
75
+ — *end example*]
76
+
77
+ **Change:** Evaluation of operands in `typeid`. **Rationale:** Introduce
78
+ additional expression value categories. **Effect on original feature:**
79
+ Valid C++03 code that uses xvalues as operands for `typeid` may change
80
+ behavior in this revision of C++.
81
+
82
+ [*Example 2*:
83
+
84
+ ``` cpp
85
+ void f() {
86
+ struct B {
87
+ B() {}
88
+ virtual ~B() { }
89
+ };
90
+
91
+ struct C { B b; };
92
+ typeid(C().b); // unevaluated in C++03{}, evaluated in C++11{}
93
+ }
94
+ ```
95
+
96
+ — *end example*]
97
+
98
  **Change:** Specify rounding for results of integer `/` and `%`.
99
  **Rationale:** Increase portability, C99 compatibility. **Effect on
100
  original feature:** Valid C++03 code that uses integer division rounds
101
  the result toward 0 or toward negative infinity, whereas this revision
102
  of C++ always rounds the result toward 0.
103
 
104
  **Change:** `&&` is valid in a *type-name*. **Rationale:** Required for
105
  new features. **Effect on original feature:** Valid C++03 code may fail
106
+ to compile or produce different results in this revision of C++.
107
+
108
+ [*Example 3*:
109
 
110
  ``` cpp
111
  bool b1 = new int && false; // previously false, now ill-formed
112
  struct S { operator int(); };
113
  bool b2 = &S::operator int && false; // previously false, now ill-formed
114
  ```
115
 
116
+ *end example*]
117
+
118
+ **Change:** Fewer copies in the conditional operator. **Rationale:**
119
+ Introduce additional expression value categories. **Effect on original
120
+ feature:** Valid C++03 code that uses xvalues as operands for the
121
+ conditional operator may change behavior in this revision of C++.
122
+
123
+ [*Example 4*:
124
+
125
+ ``` cpp
126
+ void f() {
127
+ struct B {
128
+ B() {}
129
+ B(const B&) { }
130
+ };
131
+ struct D : B {};
132
+
133
+ struct BB { B b; };
134
+ struct DD { D d; };
135
+
136
+ true ? BB().b : DD().d; // additional copy in C++03{}, no copy or move in C++11{}
137
+ }
138
+ ```
139
+
140
+ — *end example*]
141
+
142
+ ### [[dcl]]: declarations <a id="diff.cpp03.dcl.dcl">[[diff.cpp03.dcl.dcl]]</a>
143
 
144
  **Change:** Remove `auto` as a storage class specifier. **Rationale:**
145
  New feature. **Effect on original feature:** Valid C++03 code that uses
146
  the keyword `auto` as a storage class specifier may be invalid in this
147
  revision of C++. In this revision of C++, `auto` indicates that the type
148
  of a variable is to be deduced from its initializer expression.
149
 
150
  **Change:** Narrowing restrictions in aggregate initializers.
151
  **Rationale:** Catches bugs. **Effect on original feature:** Valid C++03
152
+ code may fail to compile in this revision of C++.
153
+
154
+ [*Example 1*:
155
 
156
  ``` cpp
157
  int x[] = { 2.0 };
158
  ```
159
 
160
  This code is valid in C++03 but invalid in this revision of C++ because
161
  `double` to `int` is a narrowing conversion.
162
 
163
+ — *end example*]
164
+
165
+ **Change:** Names declared in an anonymous namespace changed from
166
+ external linkage to internal linkage; language linkage applies to names
167
+ with external linkage only. **Rationale:** Alignment with user
168
+ expectations. **Effect on original feature:** Valid C++03 code may
169
+ violate the one-definition rule [[basic.def.odr]] in this revision of
170
+ C++.
171
+
172
+ [*Example 2*:
173
+
174
+ ``` cpp
175
+ namespace { extern "C" { extern int x; } } // #1, previously external linkage and C language linkage,
176
+ // now internal linkage and C++{} language linkage
177
+ namespace A { extern "C" int x = 42; } // #2, external linkage and C language linkage
178
+ int main(void) { return x; }
179
+ ```
180
+
181
+ This code is valid in C++03, but `#2` is not a definition for `#1` in
182
+ this revision of C++, violating the one-definition rule.
183
+
184
+ — *end example*]
185
+
186
  ### [[class]]: classes <a id="diff.cpp03.class">[[diff.cpp03.class]]</a>
187
 
188
  **Change:** Implicitly-declared special member functions are defined as
189
  deleted when the implicit definition would have been ill-formed.
190
  **Rationale:** Improves template argument deduction failure. **Effect on
 
212
  right angle brackets. **Rationale:** Considered a persistent but minor
213
  annoyance. Template aliases representing non-class types would
214
  exacerbate whitespace issues. **Effect on original feature:** Change to
215
  semantics of well-defined expression. A valid C++03 expression
216
  containing a right angle bracket (“`>`”) followed immediately by another
217
+ right angle bracket may now be treated as closing two templates.
218
+
219
+ [*Example 1*:
220
 
221
  ``` cpp
222
  template <class T> struct X { };
223
  template <int N> struct Y { };
224
  X< Y< 1 >> 2 > > x;
225
  ```
226
 
227
  This code is valid in C++03 because “`>>`” is a right-shift operator,
228
  but invalid in this revision of C++ because “`>>`” closes two templates.
229
 
230
+ — *end example*]
231
+
232
  **Change:** Allow dependent calls of functions with internal linkage.
233
  **Rationale:** Overly constrained, simplify overload resolution rules.
234
  **Effect on original feature:** A valid C++03 program can get a
235
  different result in this revision of C++.
236
 
237
  ### [[library]]: library introduction <a id="diff.cpp03.library">[[diff.cpp03.library]]</a>
238
 
239
+ **Affected:** [[library]] – [[exec]] **Change:** New reserved
240
  identifiers. **Rationale:** Required by new features. **Effect on
241
  original feature:** Valid C++03 code that uses any identifiers added to
242
  the C++ standard library by later revisions of C++ may fail to compile
243
  or produce different results in this revision of C++. A comprehensive
244
  list of identifiers used by the C++ standard library can be found in the
245
  Index of Library Names in this document.
246
 
247
  **Change:** New headers. **Rationale:** New functionality. **Effect on
248
  original feature:** The following C++ headers are new: `<array>`,
249
+ `<atomic>`, `<chrono>`, `<condition_variable>`, `<forward_list>`,
250
+ `<future>`, , `<mutex>`, `<random>`, `<ratio>`, `<regex>`,
251
+ `<scoped_allocator>`, `<system_error>`, `<thread>`, `<tuple>`, ,
252
+ `<type_traits>`, `<unordered_map>`, and `<unordered_set>`. In addition
253
+ the following C compatibility headers are new: `<cfenv>`, `<cinttypes>`,
254
+ `<cstdint>`, and `<cuchar>`. Valid C++03 code that `#include`s headers
255
+ with these names may be invalid in this revision of C++.
 
256
 
257
+ **Change:** Function `swap` moved to a different header. **Rationale:**
258
+ Remove dependency on `<algorithm>` for `swap`. **Effect on original
259
+ feature:** Valid C++03 code that has been compiled expecting `swap` to
260
+ be in `<algorithm>` may have to instead include `<utility>`.
 
261
 
262
  **Change:** New reserved namespace. **Rationale:** New functionality.
263
  **Effect on original feature:** The global namespace `posix` is now
264
  reserved for standardization. Valid C++03 code that uses a top-level
265
  namespace `posix` may be invalid in this revision of C++.
266
 
267
  **Change:** Additional restrictions on macro names. **Rationale:** Avoid
268
  hard to diagnose or non-portable constructs. **Effect on original
269
  feature:** Names of attribute identifiers may not be used as macro
270
+ names. Valid C++03 code that defines `override`, `final`, or `noreturn`
271
+ as macros is invalid in this revision of C++.
 
272
 
273
  ### [[support]]: language support library <a id="diff.cpp03.language.support">[[diff.cpp03.language.support]]</a>
274
 
275
  **Change:** `operator new` may throw exceptions other than
276
  `std::bad_alloc`. **Rationale:** Consistent application of `noexcept`.
 
393
  representation of the required template specializations of
394
  `std::complex` may not be compatible with this revision of C++.
395
 
396
  ### [[localization]]: localization library <a id="diff.cpp03.locale">[[diff.cpp03.locale]]</a>
397
 
398
+ **Change:** The `num_get` facet recognizes hexadecimal floating-point
399
  values. **Rationale:** Required by new feature. **Effect on original
400
  feature:** Valid C++03 code may have different behavior in this revision
401
  of C++.
402
 
403
  ### [[input.output]]: input/output library <a id="diff.cpp03.input.output">[[diff.cpp03.input.output]]</a>
 
424
 
425
  **Change:** Flag types in `std::ios_base` are now bitmasks with values
426
  defined as constexpr static members. **Rationale:** Required for new
427
  features. **Effect on original feature:** Valid C++03 code that relies
428
  on `std::ios_base` flag types being represented as `std::bitset` or as
429
+ an integer type may fail to compile with this revision of C++.
430
+
431
+ [*Example 1*:
432
 
433
  ``` cpp
434
  #include <iostream>
435
 
436
  int main() {
437
  int flag = std::ios_base::hex;
438
  std::cout.setf(flag); // error: setf does not take argument of type int
439
  }
440
  ```
441
 
442
+ — *end example*]
443
+