tmp/tmp_ndcz0q4/{from.md → to.md}
RENAMED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
## C++ and ISO C++14 <a id="diff.cpp14">[[diff.cpp14]]</a>
|
| 2 |
|
| 3 |
### General <a id="diff.cpp14.general">[[diff.cpp14.general]]</a>
|
| 4 |
|
| 5 |
-
Subclause [[diff.cpp14]] lists the differences between C++ and ISO
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
### [[lex]]: lexical conventions <a id="diff.cpp14.lex">[[diff.cpp14.lex]]</a>
|
| 10 |
|
| 11 |
**Change:** Removal of trigraph support as a required feature.
|
| 12 |
**Rationale:** Prevents accidental uses of trigraphs in non-raw string
|
|
@@ -21,17 +21,21 @@ characters to the translation character set.
|
|
| 21 |
**Rationale:** Necessary to enable
|
| 22 |
*hexadecimal-floating-point-literal*s. **Effect on original feature:**
|
| 23 |
Valid C++14 code may fail to compile or produce different results in
|
| 24 |
this revision of C++. Specifically, character sequences like `0p+0` and
|
| 25 |
`0e1_p+0` are three separate tokens each in C++14, but one single token
|
| 26 |
-
in this revision of C++.
|
|
|
|
|
|
|
| 27 |
|
| 28 |
``` cpp
|
| 29 |
#define F(a) b ## a
|
| 30 |
int b0p = F(0p+0); // ill-formed; equivalent to ``int b0p = b0p + 0;'' in C++14{}
|
| 31 |
```
|
| 32 |
|
|
|
|
|
|
|
| 33 |
### [[expr]]: expressions <a id="diff.cpp14.expr">[[diff.cpp14.expr]]</a>
|
| 34 |
|
| 35 |
**Change:** Remove increment operator with `bool` operand.
|
| 36 |
**Rationale:** Obsolete feature with occasionally surprising semantics.
|
| 37 |
**Effect on original feature:** A valid C++14 expression utilizing the
|
|
@@ -44,11 +48,11 @@ feature:** In C++14 code that uses a *new-expression* to allocate an
|
|
| 44 |
object with an over-aligned class type, where that class has no
|
| 45 |
allocation functions of its own, `::operator new(std::size_t)` is used
|
| 46 |
to allocate the memory. In this revision of C++,
|
| 47 |
`::operator new(std::size_t, std::align_val_t)` is used instead.
|
| 48 |
|
| 49 |
-
### [[dcl
|
| 50 |
|
| 51 |
**Change:** Removal of `register` *storage-class-specifier*.
|
| 52 |
**Rationale:** Enable repurposing of deprecated keyword in future
|
| 53 |
revisions of C++. **Effect on original feature:** A valid C++14
|
| 54 |
declaration utilizing the `register` *storage-class-specifier* is
|
|
@@ -56,36 +60,46 @@ ill-formed in this revision of C++. The specifier can simply be removed
|
|
| 56 |
to retain the original meaning.
|
| 57 |
|
| 58 |
**Change:** `auto` deduction from *braced-init-list*. **Rationale:**
|
| 59 |
More intuitive deduction behavior. **Effect on original feature:** Valid
|
| 60 |
C++14 code may fail to compile or may change meaning in this revision of
|
| 61 |
-
C++.
|
|
|
|
|
|
|
| 62 |
|
| 63 |
``` cpp
|
| 64 |
auto x1{1}; // was std::initializer_list<int>, now int
|
| 65 |
auto x2{1, 2}; // was std::initializer_list<int>, now ill-formed
|
| 66 |
```
|
| 67 |
|
|
|
|
|
|
|
| 68 |
**Change:** Make exception specifications be part of the type system.
|
| 69 |
**Rationale:** Improve type-safety. **Effect on original feature:**
|
| 70 |
Valid C++14 code may fail to compile or change meaning in this revision
|
| 71 |
-
of C++.
|
|
|
|
|
|
|
| 72 |
|
| 73 |
``` cpp
|
| 74 |
void g1() noexcept;
|
| 75 |
void g2();
|
| 76 |
template<class T> int f(T *, T *);
|
| 77 |
int x = f(g1, g2); // ill-formed; previously well-formed
|
| 78 |
```
|
| 79 |
|
|
|
|
|
|
|
| 80 |
**Change:** Definition of an aggregate is extended to apply to
|
| 81 |
user-defined types with base classes. **Rationale:** To increase
|
| 82 |
convenience of aggregate initialization. **Effect on original feature:**
|
| 83 |
Valid C++14 code may fail to compile or produce different results in
|
| 84 |
this revision of C++; initialization from an empty initializer list will
|
| 85 |
perform aggregate initialization instead of invoking a default
|
| 86 |
-
constructor for the affected types.
|
|
|
|
|
|
|
| 87 |
|
| 88 |
``` cpp
|
| 89 |
struct derived;
|
| 90 |
struct base {
|
| 91 |
friend struct derived;
|
|
@@ -96,20 +110,24 @@ struct derived : base {};
|
|
| 96 |
|
| 97 |
derived d1{}; // error; the code was well-formed in C++14{}
|
| 98 |
derived d2; // still OK
|
| 99 |
```
|
| 100 |
|
|
|
|
|
|
|
| 101 |
### [[class]]: classes <a id="diff.cpp14.class">[[diff.cpp14.class]]</a>
|
| 102 |
|
| 103 |
**Change:** Inheriting a constructor no longer injects a constructor
|
| 104 |
into the derived class. **Rationale:** Better interaction with other
|
| 105 |
language features. **Effect on original feature:** Valid C++14 code that
|
| 106 |
uses inheriting constructors may not be valid or may have different
|
| 107 |
semantics. A *using-declaration* that names a constructor now makes the
|
| 108 |
corresponding base class constructors visible to initializations of the
|
| 109 |
derived class rather than declaring additional derived class
|
| 110 |
-
constructors.
|
|
|
|
|
|
|
| 111 |
|
| 112 |
``` cpp
|
| 113 |
struct A {
|
| 114 |
template<typename T> A(T, typename T::type = 0);
|
| 115 |
A(int);
|
|
@@ -121,29 +139,34 @@ struct B : A {
|
|
| 121 |
B b(42L); // now calls B(int), used to call B<long>(long),
|
| 122 |
// which called A(int) due to substitution failure
|
| 123 |
// in A<long>(long).
|
| 124 |
```
|
| 125 |
|
|
|
|
|
|
|
| 126 |
### [[temp]]: templates <a id="diff.cpp14.temp">[[diff.cpp14.temp]]</a>
|
| 127 |
|
| 128 |
-
**Change:** Allowance to deduce from the type of a
|
| 129 |
argument. **Rationale:** In combination with the ability to declare
|
| 130 |
-
|
| 131 |
-
specializations to decompose from the type deduced for the
|
| 132 |
template argument. **Effect on original feature:** Valid C++14 code may
|
| 133 |
fail to compile or produce different results in this revision of C++.
|
| 134 |
-
|
|
|
|
| 135 |
|
| 136 |
``` cpp
|
| 137 |
template <int N> struct A;
|
| 138 |
template <typename T, T N> int foo(A<N> *) = delete;
|
| 139 |
void foo(void *);
|
| 140 |
void bar(A<0> *p) {
|
| 141 |
foo(p); // ill-formed; previously well-formed
|
| 142 |
}
|
| 143 |
```
|
| 144 |
|
|
|
|
|
|
|
| 145 |
### [[except]]: exception handling <a id="diff.cpp14.except">[[diff.cpp14.except]]</a>
|
| 146 |
|
| 147 |
**Change:** Remove dynamic exception specifications. **Rationale:**
|
| 148 |
Dynamic exception specifications were a deprecated feature that was
|
| 149 |
complex and brittle in use. They interacted badly with the type system,
|
|
@@ -185,42 +208,51 @@ ill-formed and uses-allocator construction will not pass an allocator to
|
|
| 185 |
|
| 186 |
**Change:** Different constraint on conversions from `unique_ptr`.
|
| 187 |
**Rationale:** Adding array support to `shared_ptr`, via the syntax
|
| 188 |
`shared_ptr<T[]>` and `shared_ptr<T[N]>`. **Effect on original
|
| 189 |
feature:** Valid C++14 code may fail to compile or may change meaning in
|
| 190 |
-
this revision of C++.
|
|
|
|
|
|
|
| 191 |
|
| 192 |
``` cpp
|
| 193 |
#include <memory>
|
| 194 |
std::unique_ptr<int[]> arr(new int[1]);
|
| 195 |
std::shared_ptr<int> ptr(std::move(arr)); // error: int(*)[] is not compatible with int*
|
| 196 |
```
|
| 197 |
|
|
|
|
|
|
|
| 198 |
### [[strings]]: strings library <a id="diff.cpp14.string">[[diff.cpp14.string]]</a>
|
| 199 |
|
| 200 |
**Change:** Non-const `.data()` member added. **Rationale:** The lack of
|
| 201 |
a non-const `.data()` differed from the similar member of `std::vector`.
|
| 202 |
This change regularizes behavior. **Effect on original feature:**
|
| 203 |
Overloaded functions which have differing code paths for `char*` and
|
| 204 |
`const char*` arguments will execute differently when called with a
|
| 205 |
-
non-const string’s `.data()` member in this revision of C++.
|
| 206 |
-
|
|
|
|
| 207 |
|
| 208 |
``` cpp
|
| 209 |
int f(char *) = delete;
|
| 210 |
int f(const char *);
|
| 211 |
string s;
|
| 212 |
int x = f(s.data()); // ill-formed; previously well-formed
|
| 213 |
```
|
| 214 |
|
|
|
|
|
|
|
| 215 |
### [[containers]]: containers library <a id="diff.cpp14.containers">[[diff.cpp14.containers]]</a>
|
| 216 |
|
| 217 |
**Change:** Requirements change: **Rationale:** Increase portability,
|
| 218 |
clarification of associative container requirements. **Effect on
|
| 219 |
original feature:** Valid C++14 code that attempts to use associative
|
| 220 |
containers having a comparison object with non-const function call
|
| 221 |
-
operator may fail to compile in this revision of C++.
|
|
|
|
|
|
|
| 222 |
|
| 223 |
``` cpp
|
| 224 |
#include <set>
|
| 225 |
|
| 226 |
struct compare
|
|
@@ -235,10 +267,12 @@ int main() {
|
|
| 235 |
const std::set<int, compare> s;
|
| 236 |
s.find(0);
|
| 237 |
}
|
| 238 |
```
|
| 239 |
|
|
|
|
|
|
|
| 240 |
### [[depr]]: compatibility features <a id="diff.cpp14.depr">[[diff.cpp14.depr]]</a>
|
| 241 |
|
| 242 |
**Change:** The class templates `auto_ptr`, `unary_function`, and
|
| 243 |
`binary_function`, the function templates `random_shuffle`, and the
|
| 244 |
function templates (and their return types) `ptr_fun`, `mem_fun`,
|
|
|
|
| 1 |
## C++ and ISO C++14 <a id="diff.cpp14">[[diff.cpp14]]</a>
|
| 2 |
|
| 3 |
### General <a id="diff.cpp14.general">[[diff.cpp14.general]]</a>
|
| 4 |
|
| 5 |
+
Subclause [[diff.cpp14]] lists the differences between C++ and ISO
|
| 6 |
+
C++14, in addition to those listed above, by the chapters of this
|
| 7 |
+
document.
|
| 8 |
|
| 9 |
### [[lex]]: lexical conventions <a id="diff.cpp14.lex">[[diff.cpp14.lex]]</a>
|
| 10 |
|
| 11 |
**Change:** Removal of trigraph support as a required feature.
|
| 12 |
**Rationale:** Prevents accidental uses of trigraphs in non-raw string
|
|
|
|
| 21 |
**Rationale:** Necessary to enable
|
| 22 |
*hexadecimal-floating-point-literal*s. **Effect on original feature:**
|
| 23 |
Valid C++14 code may fail to compile or produce different results in
|
| 24 |
this revision of C++. Specifically, character sequences like `0p+0` and
|
| 25 |
`0e1_p+0` are three separate tokens each in C++14, but one single token
|
| 26 |
+
in this revision of C++.
|
| 27 |
+
|
| 28 |
+
[*Example 1*:
|
| 29 |
|
| 30 |
``` cpp
|
| 31 |
#define F(a) b ## a
|
| 32 |
int b0p = F(0p+0); // ill-formed; equivalent to ``int b0p = b0p + 0;'' in C++14{}
|
| 33 |
```
|
| 34 |
|
| 35 |
+
— *end example*]
|
| 36 |
+
|
| 37 |
### [[expr]]: expressions <a id="diff.cpp14.expr">[[diff.cpp14.expr]]</a>
|
| 38 |
|
| 39 |
**Change:** Remove increment operator with `bool` operand.
|
| 40 |
**Rationale:** Obsolete feature with occasionally surprising semantics.
|
| 41 |
**Effect on original feature:** A valid C++14 expression utilizing the
|
|
|
|
| 48 |
object with an over-aligned class type, where that class has no
|
| 49 |
allocation functions of its own, `::operator new(std::size_t)` is used
|
| 50 |
to allocate the memory. In this revision of C++,
|
| 51 |
`::operator new(std::size_t, std::align_val_t)` is used instead.
|
| 52 |
|
| 53 |
+
### [[dcl]]: declarations <a id="diff.cpp14.dcl.dcl">[[diff.cpp14.dcl.dcl]]</a>
|
| 54 |
|
| 55 |
**Change:** Removal of `register` *storage-class-specifier*.
|
| 56 |
**Rationale:** Enable repurposing of deprecated keyword in future
|
| 57 |
revisions of C++. **Effect on original feature:** A valid C++14
|
| 58 |
declaration utilizing the `register` *storage-class-specifier* is
|
|
|
|
| 60 |
to retain the original meaning.
|
| 61 |
|
| 62 |
**Change:** `auto` deduction from *braced-init-list*. **Rationale:**
|
| 63 |
More intuitive deduction behavior. **Effect on original feature:** Valid
|
| 64 |
C++14 code may fail to compile or may change meaning in this revision of
|
| 65 |
+
C++.
|
| 66 |
+
|
| 67 |
+
[*Example 1*:
|
| 68 |
|
| 69 |
``` cpp
|
| 70 |
auto x1{1}; // was std::initializer_list<int>, now int
|
| 71 |
auto x2{1, 2}; // was std::initializer_list<int>, now ill-formed
|
| 72 |
```
|
| 73 |
|
| 74 |
+
— *end example*]
|
| 75 |
+
|
| 76 |
**Change:** Make exception specifications be part of the type system.
|
| 77 |
**Rationale:** Improve type-safety. **Effect on original feature:**
|
| 78 |
Valid C++14 code may fail to compile or change meaning in this revision
|
| 79 |
+
of C++.
|
| 80 |
+
|
| 81 |
+
[*Example 2*:
|
| 82 |
|
| 83 |
``` cpp
|
| 84 |
void g1() noexcept;
|
| 85 |
void g2();
|
| 86 |
template<class T> int f(T *, T *);
|
| 87 |
int x = f(g1, g2); // ill-formed; previously well-formed
|
| 88 |
```
|
| 89 |
|
| 90 |
+
— *end example*]
|
| 91 |
+
|
| 92 |
**Change:** Definition of an aggregate is extended to apply to
|
| 93 |
user-defined types with base classes. **Rationale:** To increase
|
| 94 |
convenience of aggregate initialization. **Effect on original feature:**
|
| 95 |
Valid C++14 code may fail to compile or produce different results in
|
| 96 |
this revision of C++; initialization from an empty initializer list will
|
| 97 |
perform aggregate initialization instead of invoking a default
|
| 98 |
+
constructor for the affected types.
|
| 99 |
+
|
| 100 |
+
[*Example 3*:
|
| 101 |
|
| 102 |
``` cpp
|
| 103 |
struct derived;
|
| 104 |
struct base {
|
| 105 |
friend struct derived;
|
|
|
|
| 110 |
|
| 111 |
derived d1{}; // error; the code was well-formed in C++14{}
|
| 112 |
derived d2; // still OK
|
| 113 |
```
|
| 114 |
|
| 115 |
+
— *end example*]
|
| 116 |
+
|
| 117 |
### [[class]]: classes <a id="diff.cpp14.class">[[diff.cpp14.class]]</a>
|
| 118 |
|
| 119 |
**Change:** Inheriting a constructor no longer injects a constructor
|
| 120 |
into the derived class. **Rationale:** Better interaction with other
|
| 121 |
language features. **Effect on original feature:** Valid C++14 code that
|
| 122 |
uses inheriting constructors may not be valid or may have different
|
| 123 |
semantics. A *using-declaration* that names a constructor now makes the
|
| 124 |
corresponding base class constructors visible to initializations of the
|
| 125 |
derived class rather than declaring additional derived class
|
| 126 |
+
constructors.
|
| 127 |
+
|
| 128 |
+
[*Example 1*:
|
| 129 |
|
| 130 |
``` cpp
|
| 131 |
struct A {
|
| 132 |
template<typename T> A(T, typename T::type = 0);
|
| 133 |
A(int);
|
|
|
|
| 139 |
B b(42L); // now calls B(int), used to call B<long>(long),
|
| 140 |
// which called A(int) due to substitution failure
|
| 141 |
// in A<long>(long).
|
| 142 |
```
|
| 143 |
|
| 144 |
+
— *end example*]
|
| 145 |
+
|
| 146 |
### [[temp]]: templates <a id="diff.cpp14.temp">[[diff.cpp14.temp]]</a>
|
| 147 |
|
| 148 |
+
**Change:** Allowance to deduce from the type of a constant template
|
| 149 |
argument. **Rationale:** In combination with the ability to declare
|
| 150 |
+
constant template arguments with placeholder types, allows partial
|
| 151 |
+
specializations to decompose from the type deduced for the constant
|
| 152 |
template argument. **Effect on original feature:** Valid C++14 code may
|
| 153 |
fail to compile or produce different results in this revision of C++.
|
| 154 |
+
|
| 155 |
+
[*Example 1*:
|
| 156 |
|
| 157 |
``` cpp
|
| 158 |
template <int N> struct A;
|
| 159 |
template <typename T, T N> int foo(A<N> *) = delete;
|
| 160 |
void foo(void *);
|
| 161 |
void bar(A<0> *p) {
|
| 162 |
foo(p); // ill-formed; previously well-formed
|
| 163 |
}
|
| 164 |
```
|
| 165 |
|
| 166 |
+
— *end example*]
|
| 167 |
+
|
| 168 |
### [[except]]: exception handling <a id="diff.cpp14.except">[[diff.cpp14.except]]</a>
|
| 169 |
|
| 170 |
**Change:** Remove dynamic exception specifications. **Rationale:**
|
| 171 |
Dynamic exception specifications were a deprecated feature that was
|
| 172 |
complex and brittle in use. They interacted badly with the type system,
|
|
|
|
| 208 |
|
| 209 |
**Change:** Different constraint on conversions from `unique_ptr`.
|
| 210 |
**Rationale:** Adding array support to `shared_ptr`, via the syntax
|
| 211 |
`shared_ptr<T[]>` and `shared_ptr<T[N]>`. **Effect on original
|
| 212 |
feature:** Valid C++14 code may fail to compile or may change meaning in
|
| 213 |
+
this revision of C++.
|
| 214 |
+
|
| 215 |
+
[*Example 1*:
|
| 216 |
|
| 217 |
``` cpp
|
| 218 |
#include <memory>
|
| 219 |
std::unique_ptr<int[]> arr(new int[1]);
|
| 220 |
std::shared_ptr<int> ptr(std::move(arr)); // error: int(*)[] is not compatible with int*
|
| 221 |
```
|
| 222 |
|
| 223 |
+
— *end example*]
|
| 224 |
+
|
| 225 |
### [[strings]]: strings library <a id="diff.cpp14.string">[[diff.cpp14.string]]</a>
|
| 226 |
|
| 227 |
**Change:** Non-const `.data()` member added. **Rationale:** The lack of
|
| 228 |
a non-const `.data()` differed from the similar member of `std::vector`.
|
| 229 |
This change regularizes behavior. **Effect on original feature:**
|
| 230 |
Overloaded functions which have differing code paths for `char*` and
|
| 231 |
`const char*` arguments will execute differently when called with a
|
| 232 |
+
non-const string’s `.data()` member in this revision of C++.
|
| 233 |
+
|
| 234 |
+
[*Example 1*:
|
| 235 |
|
| 236 |
``` cpp
|
| 237 |
int f(char *) = delete;
|
| 238 |
int f(const char *);
|
| 239 |
string s;
|
| 240 |
int x = f(s.data()); // ill-formed; previously well-formed
|
| 241 |
```
|
| 242 |
|
| 243 |
+
— *end example*]
|
| 244 |
+
|
| 245 |
### [[containers]]: containers library <a id="diff.cpp14.containers">[[diff.cpp14.containers]]</a>
|
| 246 |
|
| 247 |
**Change:** Requirements change: **Rationale:** Increase portability,
|
| 248 |
clarification of associative container requirements. **Effect on
|
| 249 |
original feature:** Valid C++14 code that attempts to use associative
|
| 250 |
containers having a comparison object with non-const function call
|
| 251 |
+
operator may fail to compile in this revision of C++.
|
| 252 |
+
|
| 253 |
+
[*Example 1*:
|
| 254 |
|
| 255 |
``` cpp
|
| 256 |
#include <set>
|
| 257 |
|
| 258 |
struct compare
|
|
|
|
| 267 |
const std::set<int, compare> s;
|
| 268 |
s.find(0);
|
| 269 |
}
|
| 270 |
```
|
| 271 |
|
| 272 |
+
— *end example*]
|
| 273 |
+
|
| 274 |
### [[depr]]: compatibility features <a id="diff.cpp14.depr">[[diff.cpp14.depr]]</a>
|
| 275 |
|
| 276 |
**Change:** The class templates `auto_ptr`, `unary_function`, and
|
| 277 |
`binary_function`, the function templates `random_shuffle`, and the
|
| 278 |
function templates (and their return types) `ptr_fun`, `mem_fun`,
|