- tmp/tmpxzlqjy90/{from.md → to.md} +107 -39
tmp/tmpxzlqjy90/{from.md → to.md}
RENAMED
|
@@ -1,19 +1,21 @@
|
|
| 1 |
## C++ and ISO C++17 <a id="diff.cpp17">[[diff.cpp17]]</a>
|
| 2 |
|
| 3 |
### General <a id="diff.cpp17.general">[[diff.cpp17.general]]</a>
|
| 4 |
|
| 5 |
-
Subclause [[diff.cpp17]] lists the differences between C++ and ISO
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
### [[lex]]: lexical conventions <a id="diff.cpp17.lex">[[diff.cpp17.lex]]</a>
|
| 10 |
|
| 11 |
**Change:** New identifiers with special meaning. **Rationale:**
|
| 12 |
Required for new features. **Effect on original feature:** Logical lines
|
| 13 |
beginning with `module` or `import` may be interpreted differently in
|
| 14 |
-
this revision of C++.
|
|
|
|
|
|
|
| 15 |
|
| 16 |
``` cpp
|
| 17 |
class module {};
|
| 18 |
module m1; // was variable declaration; now module-declaration
|
| 19 |
module *m2; // variable declaration
|
|
@@ -21,21 +23,27 @@ module *m2; // variable declaration
|
|
| 21 |
class import {};
|
| 22 |
import j1; // was variable declaration; now module-import-declaration
|
| 23 |
::import j2; // variable declaration
|
| 24 |
```
|
| 25 |
|
|
|
|
|
|
|
| 26 |
**Change:** *header-name* tokens are formed in more contexts.
|
| 27 |
**Rationale:** Required for new features. **Effect on original
|
| 28 |
feature:** When the identifier `import` is followed by a `<` character,
|
| 29 |
-
a *header-name* token may be formed.
|
|
|
|
|
|
|
| 30 |
|
| 31 |
``` cpp
|
| 32 |
template<typename> class import {};
|
| 33 |
import<int> f(); // ill-formed; previously well-formed
|
| 34 |
::import<int> g(); // OK
|
| 35 |
```
|
| 36 |
|
|
|
|
|
|
|
| 37 |
**Change:** New keywords. **Rationale:** Required for new features.
|
| 38 |
|
| 39 |
- The `char8_t` keyword is added to differentiate the types of ordinary
|
| 40 |
and UTF-8 literals [[lex.string]].
|
| 41 |
- The `concept` keyword is added to enable the definition of concepts
|
|
@@ -55,29 +63,34 @@ Valid C++17 code using `char8_t`, `concept`, `consteval`, `constinit`,
|
|
| 55 |
not valid in this revision of C++.
|
| 56 |
|
| 57 |
**Change:** New operator `<=>`. **Rationale:** Necessary for new
|
| 58 |
functionality. **Effect on original feature:** Valid C++17 code that
|
| 59 |
contains a `<=` token immediately followed by a `>` token may be
|
| 60 |
-
ill-formed or have different semantics in this revision of C++.
|
| 61 |
-
|
|
|
|
| 62 |
|
| 63 |
``` cpp
|
| 64 |
namespace N {
|
| 65 |
struct X {};
|
| 66 |
bool operator<=(X, X);
|
| 67 |
template<bool(X, X)> struct Y {};
|
| 68 |
Y<operator<=> y; // ill-formed; previously well-formed
|
| 69 |
}
|
| 70 |
```
|
| 71 |
|
|
|
|
|
|
|
| 72 |
**Change:** Type of UTF-8 string and character literals. **Rationale:**
|
| 73 |
Required for new features. The changed types enable function
|
| 74 |
overloading, template specialization, and type deduction to distinguish
|
| 75 |
ordinary and UTF-8 string and character literals. **Effect on original
|
| 76 |
feature:** Valid C++17 code that depends on UTF-8 string literals having
|
| 77 |
type “array of `const char`” and UTF-8 character literals having type
|
| 78 |
-
“`char`” is not valid in this revision of C++.
|
|
|
|
|
|
|
| 79 |
|
| 80 |
``` cpp
|
| 81 |
const auto *u8s = u8"text"; // u8s previously deduced as const char*; now deduced as const char8_t*
|
| 82 |
const char *ps = u8s; // ill-formed; previously well-formed
|
| 83 |
|
|
@@ -94,27 +107,32 @@ template<> struct ct<char> {
|
|
| 94 |
using type = char;
|
| 95 |
};
|
| 96 |
ct<decltype(u8'c')>::type x; // ill-formed; previously well-formed.
|
| 97 |
```
|
| 98 |
|
|
|
|
|
|
|
| 99 |
### [[basic]]: basics <a id="diff.cpp17.basic">[[diff.cpp17.basic]]</a>
|
| 100 |
|
| 101 |
**Change:** A pseudo-destructor call ends the lifetime of the object to
|
| 102 |
which it is applied. **Rationale:** Increase consistency of the language
|
| 103 |
model. **Effect on original feature:** Valid ISO C++17 code may be
|
| 104 |
-
ill-formed or have undefined behavior in this revision of C++.
|
| 105 |
-
|
|
|
|
| 106 |
|
| 107 |
``` cpp
|
| 108 |
int f() {
|
| 109 |
int a = 123;
|
| 110 |
using T = int;
|
| 111 |
a.~T();
|
| 112 |
return a; // undefined behavior; previously returned 123
|
| 113 |
}
|
| 114 |
```
|
| 115 |
|
|
|
|
|
|
|
| 116 |
**Change:** Except for the initial release operation, a release sequence
|
| 117 |
consists solely of atomic read-modify-write operations. **Rationale:**
|
| 118 |
Removal of rarely used and confusing feature. **Effect on original
|
| 119 |
feature:** If a `memory_order_release` atomic store is followed by a
|
| 120 |
`memory_order_relaxed` store to the same variable by the same thread,
|
|
@@ -129,28 +147,33 @@ intervening stores by another thread.
|
|
| 129 |
with constexpr if. **Effect on original feature:** Lambdas with a
|
| 130 |
*capture-default* may capture local entities that were not captured in
|
| 131 |
C++17 if those entities are only referenced in contexts that do not
|
| 132 |
result in an odr-use.
|
| 133 |
|
| 134 |
-
### [[dcl
|
| 135 |
|
| 136 |
**Change:** Unnamed classes with a typedef name for linkage purposes can
|
| 137 |
contain only C-compatible constructs. **Rationale:** Necessary for
|
| 138 |
implementability. **Effect on original feature:** Valid C++17 code may
|
| 139 |
-
be ill-formed in this revision of C++.
|
|
|
|
|
|
|
| 140 |
|
| 141 |
``` cpp
|
| 142 |
typedef struct {
|
| 143 |
void f() {} // ill-formed; previously well-formed
|
| 144 |
} S;
|
| 145 |
```
|
| 146 |
|
|
|
|
|
|
|
| 147 |
**Change:** A function cannot have different default arguments in
|
| 148 |
different translation units. **Rationale:** Required for modules
|
| 149 |
support. **Effect on original feature:** Valid C++17 code may be
|
| 150 |
-
ill-formed in this revision of C++, with no diagnostic required.
|
| 151 |
-
|
|
|
|
| 152 |
|
| 153 |
``` cpp
|
| 154 |
// Translation unit 1
|
| 155 |
int f(int a = 42);
|
| 156 |
int g() { return f(); }
|
|
@@ -159,17 +182,20 @@ int g() { return f(); }
|
|
| 159 |
int f(int a = 76) { return a; } // ill-formed, no diagnostic required; previously well-formed
|
| 160 |
int g();
|
| 161 |
int main() { return g(); } // used to return 42
|
| 162 |
```
|
| 163 |
|
|
|
|
|
|
|
| 164 |
**Change:** A class that has user-declared constructors is never an
|
| 165 |
aggregate. **Rationale:** Remove potentially error-prone aggregate
|
| 166 |
initialization which may apply notwithstanding the declared constructors
|
| 167 |
of a class. **Effect on original feature:** Valid C++17 code that
|
| 168 |
aggregate-initializes a type with a user-declared constructor may be
|
| 169 |
-
ill-formed or have different semantics in this revision of C++.
|
| 170 |
-
|
|
|
|
| 171 |
|
| 172 |
``` cpp
|
| 173 |
struct A { // not an aggregate; previously an aggregate
|
| 174 |
A() = delete;
|
| 175 |
};
|
|
@@ -200,59 +226,74 @@ struct Y { // not an aggregate; previously an aggregate
|
|
| 200 |
};
|
| 201 |
|
| 202 |
Y y{X{}}; // copy constructor call; previously aggregate-initialization
|
| 203 |
```
|
| 204 |
|
|
|
|
|
|
|
| 205 |
**Change:** Boolean conversion from a pointer or pointer-to-member type
|
| 206 |
is now a narrowing conversion. **Rationale:** Catches bugs. **Effect on
|
| 207 |
original feature:** Valid C++17 code may fail to compile in this
|
| 208 |
-
revision of C++.
|
|
|
|
|
|
|
| 209 |
|
| 210 |
``` cpp
|
| 211 |
bool y[] = { "bc" }; // ill-formed; previously well-formed
|
| 212 |
```
|
| 213 |
|
|
|
|
|
|
|
| 214 |
### [[class]]: classes <a id="diff.cpp17.class">[[diff.cpp17.class]]</a>
|
| 215 |
|
| 216 |
**Change:** The class name can no longer be used parenthesized
|
| 217 |
immediately after an `explicit` *decl-specifier* in a constructor
|
| 218 |
declaration. The *conversion-function-id* can no longer be used
|
| 219 |
parenthesized immediately after an `explicit` *decl-specifier* in a
|
| 220 |
conversion function declaration. **Rationale:** Necessary for new
|
| 221 |
functionality. **Effect on original feature:** Valid C++17 code may fail
|
| 222 |
-
to compile in this revision of C++.
|
|
|
|
|
|
|
| 223 |
|
| 224 |
``` cpp
|
| 225 |
struct S {
|
| 226 |
explicit (S)(const S&); // ill-formed; previously well-formed
|
| 227 |
explicit (operator int)(); // ill-formed; previously well-formed
|
| 228 |
explicit(true) (S)(int); // OK
|
| 229 |
};
|
| 230 |
```
|
| 231 |
|
|
|
|
|
|
|
| 232 |
**Change:** A *simple-template-id* is no longer valid as the
|
| 233 |
*declarator-id* of a constructor or destructor. **Rationale:** Remove
|
| 234 |
potentially error-prone option for redundancy. **Effect on original
|
| 235 |
feature:** Valid C++17 code may fail to compile in this revision of C++.
|
| 236 |
-
|
|
|
|
| 237 |
|
| 238 |
``` cpp
|
| 239 |
template<class T>
|
| 240 |
struct A {
|
| 241 |
A<T>(); // error: simple-template-id not allowed for constructor
|
| 242 |
A(int); // OK, injected-class-name used
|
| 243 |
~A<T>(); // error: simple-template-id not allowed for destructor
|
| 244 |
};
|
| 245 |
```
|
| 246 |
|
|
|
|
|
|
|
| 247 |
**Change:** A function returning an implicitly movable entity may invoke
|
| 248 |
a constructor taking an rvalue reference to a type different from that
|
| 249 |
of the returned expression. Function and catch-clause parameters can be
|
| 250 |
thrown using move constructors. **Rationale:** Side effect of making it
|
| 251 |
easier to write more efficient code that takes advantage of moves.
|
| 252 |
**Effect on original feature:** Valid C++17 code may fail to compile or
|
| 253 |
-
have different semantics in this revision of C++.
|
|
|
|
|
|
|
| 254 |
|
| 255 |
``` cpp
|
| 256 |
struct base {
|
| 257 |
base();
|
| 258 |
base(base const &);
|
|
@@ -282,21 +323,25 @@ void g() {
|
|
| 282 |
consume(static_cast<S&&>(s));
|
| 283 |
char c = *s.m; // undefined behavior; previously ok
|
| 284 |
}
|
| 285 |
```
|
| 286 |
|
|
|
|
|
|
|
| 287 |
### [[over]]: overloading <a id="diff.cpp17.over">[[diff.cpp17.over]]</a>
|
| 288 |
|
| 289 |
**Change:** Equality and inequality expressions can now find reversed
|
| 290 |
and rewritten candidates. **Rationale:** Improve consistency of equality
|
| 291 |
with three-way comparison and make it easier to write the full
|
| 292 |
complement of equality operations. **Effect on original feature:** For
|
| 293 |
certain pairs of types where one is convertible to the other, equality
|
| 294 |
or inequality expressions between an object of one type and an object of
|
| 295 |
the other type invoke a different operator. Also, for certain types,
|
| 296 |
equality or inequality expressions between two objects of that type
|
| 297 |
-
become ambiguous.
|
|
|
|
|
|
|
| 298 |
|
| 299 |
``` cpp
|
| 300 |
struct A {
|
| 301 |
operator int() const;
|
| 302 |
};
|
|
@@ -310,15 +355,19 @@ int check(A x, A y) {
|
|
| 310 |
(10 == x) + // calls #1, previously selected #2
|
| 311 |
(10 != x); // calls #1, previously selected #3
|
| 312 |
}
|
| 313 |
```
|
| 314 |
|
|
|
|
|
|
|
| 315 |
**Change:** Overload resolution may change for equality operators
|
| 316 |
[[expr.eq]]. **Rationale:** Support calling `operator==` with reversed
|
| 317 |
order of arguments. **Effect on original feature:** Valid C++17 code
|
| 318 |
that uses equality operators with conversion functions may be ill-formed
|
| 319 |
-
or have different semantics in this revision of C++.
|
|
|
|
|
|
|
| 320 |
|
| 321 |
``` cpp
|
| 322 |
struct A {
|
| 323 |
operator int() const { return 10; }
|
| 324 |
};
|
|
@@ -332,21 +381,25 @@ struct B {
|
|
| 332 |
};
|
| 333 |
B b1;
|
| 334 |
bool eq = (b1 == b1); // ambiguous; previously well-formed
|
| 335 |
```
|
| 336 |
|
|
|
|
|
|
|
| 337 |
### [[temp]]: templates <a id="diff.cpp17.temp">[[diff.cpp17.temp]]</a>
|
| 338 |
|
| 339 |
**Change:** An *unqualified-id* that is followed by a `<` and for which
|
| 340 |
name lookup finds nothing or finds a function will be treated as a
|
| 341 |
-
*template-name* in order to potentially cause argument
|
| 342 |
to be performed. **Rationale:** It was problematic to call a function
|
| 343 |
-
template with an explicit template argument list via argument
|
| 344 |
lookup because of the need to have a template with the same name visible
|
| 345 |
via normal lookup. **Effect on original feature:** Previously valid code
|
| 346 |
that uses a function name as the left operand of a `<` operator would
|
| 347 |
-
become ill-formed.
|
|
|
|
|
|
|
| 348 |
|
| 349 |
``` cpp
|
| 350 |
struct A {};
|
| 351 |
bool operator<(void (*fp)(), A);
|
| 352 |
void f() {}
|
|
@@ -355,10 +408,12 @@ int main() {
|
|
| 355 |
f < a; // ill-formed; previously well-formed
|
| 356 |
(f) < a; // still well-formed
|
| 357 |
}
|
| 358 |
```
|
| 359 |
|
|
|
|
|
|
|
| 360 |
### [[except]]: exception handling <a id="diff.cpp17.except">[[diff.cpp17.except]]</a>
|
| 361 |
|
| 362 |
**Change:** Remove `throw()` exception specification. **Rationale:**
|
| 363 |
Removal of obsolete feature that has been replaced by `noexcept`.
|
| 364 |
**Effect on original feature:** A valid C++17 function declaration,
|
|
@@ -431,62 +486,75 @@ have undefined behavior.
|
|
| 431 |
### [[input.output]]: input/output library <a id="diff.cpp17.input.output">[[diff.cpp17.input.output]]</a>
|
| 432 |
|
| 433 |
**Change:** Character array extraction only takes array types.
|
| 434 |
**Rationale:** Increase safety via preventing buffer overflow at compile
|
| 435 |
time. **Effect on original feature:** Valid C++17 code may fail to
|
| 436 |
-
compile in this revision of C++.
|
|
|
|
|
|
|
| 437 |
|
| 438 |
``` cpp
|
| 439 |
auto p = new char[100];
|
| 440 |
char q[100];
|
| 441 |
std::cin >> std::setw(20) >> p; // ill-formed; previously well-formed
|
| 442 |
std::cin >> std::setw(20) >> q; // OK
|
| 443 |
```
|
| 444 |
|
|
|
|
|
|
|
| 445 |
**Change:** Overload resolution for ostream inserters used with UTF-8
|
| 446 |
literals. **Rationale:** Required for new features. **Effect on original
|
| 447 |
feature:** Valid C++17 code that passes UTF-8 literals to
|
| 448 |
`basic_ostream<char, ...>::operator<<` or
|
| 449 |
-
`basic_ostream<wchar_t, ...>::operator<<` is now ill-formed.
|
| 450 |
-
|
|
|
|
| 451 |
|
| 452 |
``` cpp
|
| 453 |
std::cout << u8"text"; // previously called operator<<(const char*) and printed a string;
|
| 454 |
// now ill-formed
|
| 455 |
std::cout << u8'X'; // previously called operator<<(char) and printed a character;
|
| 456 |
// now ill-formed
|
| 457 |
```
|
| 458 |
|
|
|
|
|
|
|
| 459 |
**Change:** Overload resolution for ostream inserters used with
|
| 460 |
`wchar_t`, `char16_t`, or `char32_t` types. **Rationale:** Removal of
|
| 461 |
surprising behavior. **Effect on original feature:** Valid C++17 code
|
| 462 |
that passes `wchar_t`, `char16_t`, or `char32_t` characters or strings
|
| 463 |
to `basic_ostream<char, ...>::operator<<` or that passes `char16_t` or
|
| 464 |
`char32_t` characters or strings to
|
| 465 |
-
`basic_ostream<wchar_t, ...>::operator<<` is now ill-formed.
|
| 466 |
-
|
|
|
|
| 467 |
|
| 468 |
``` cpp
|
| 469 |
std::cout << u"text"; // previously formatted the string as a pointer value;
|
| 470 |
// now ill-formed
|
| 471 |
std::cout << u'X'; // previously formatted the character as an integer value;
|
| 472 |
// now ill-formed
|
| 473 |
```
|
| 474 |
|
|
|
|
|
|
|
| 475 |
**Change:** Return type of filesystem path format observer member
|
| 476 |
functions. **Rationale:** Required for new features. **Effect on
|
| 477 |
original feature:** Valid C++17 code that depends on the `u8string()`
|
| 478 |
and `generic_u8string()` member functions of `std::filesystem::path`
|
| 479 |
-
returning `std::string` is not valid in this revision of C++.
|
| 480 |
-
|
|
|
|
| 481 |
|
| 482 |
``` cpp
|
| 483 |
std::filesystem::path p;
|
| 484 |
std::string s1 = p.u8string(); // ill-formed; previously well-formed
|
| 485 |
std::string s2 = p.generic_u8string(); // ill-formed; previously well-formed
|
| 486 |
```
|
| 487 |
|
|
|
|
|
|
|
| 488 |
### [[depr]]: compatibility features <a id="diff.cpp17.depr">[[diff.cpp17.depr]]</a>
|
| 489 |
|
| 490 |
**Change:** Remove `uncaught_exception`. **Rationale:** The function did
|
| 491 |
not have a clear specification when multiple exceptions were active, and
|
| 492 |
has been superseded by `uncaught_exceptions`. **Effect on original
|
|
@@ -536,13 +604,13 @@ available for well-defined use in single-threaded cases. **Effect on
|
|
| 536 |
original feature:** A valid C++17 program that calls `unique` on a
|
| 537 |
`shared_ptr` object may fail to compile.
|
| 538 |
|
| 539 |
**Change:** Remove deprecated type traits. **Rationale:** The traits had
|
| 540 |
unreliable or awkward interfaces. The `is_literal_type` trait provided
|
| 541 |
-
no way to detect which subset of
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
|
|
|
|
| 1 |
## C++ and ISO C++17 <a id="diff.cpp17">[[diff.cpp17]]</a>
|
| 2 |
|
| 3 |
### General <a id="diff.cpp17.general">[[diff.cpp17.general]]</a>
|
| 4 |
|
| 5 |
+
Subclause [[diff.cpp17]] lists the differences between C++ and ISO
|
| 6 |
+
C++17, in addition to those listed above, by the chapters of this
|
| 7 |
+
document.
|
| 8 |
|
| 9 |
### [[lex]]: lexical conventions <a id="diff.cpp17.lex">[[diff.cpp17.lex]]</a>
|
| 10 |
|
| 11 |
**Change:** New identifiers with special meaning. **Rationale:**
|
| 12 |
Required for new features. **Effect on original feature:** Logical lines
|
| 13 |
beginning with `module` or `import` may be interpreted differently in
|
| 14 |
+
this revision of C++.
|
| 15 |
+
|
| 16 |
+
[*Example 1*:
|
| 17 |
|
| 18 |
``` cpp
|
| 19 |
class module {};
|
| 20 |
module m1; // was variable declaration; now module-declaration
|
| 21 |
module *m2; // variable declaration
|
|
|
|
| 23 |
class import {};
|
| 24 |
import j1; // was variable declaration; now module-import-declaration
|
| 25 |
::import j2; // variable declaration
|
| 26 |
```
|
| 27 |
|
| 28 |
+
— *end example*]
|
| 29 |
+
|
| 30 |
**Change:** *header-name* tokens are formed in more contexts.
|
| 31 |
**Rationale:** Required for new features. **Effect on original
|
| 32 |
feature:** When the identifier `import` is followed by a `<` character,
|
| 33 |
+
a *header-name* token may be formed.
|
| 34 |
+
|
| 35 |
+
[*Example 2*:
|
| 36 |
|
| 37 |
``` cpp
|
| 38 |
template<typename> class import {};
|
| 39 |
import<int> f(); // ill-formed; previously well-formed
|
| 40 |
::import<int> g(); // OK
|
| 41 |
```
|
| 42 |
|
| 43 |
+
— *end example*]
|
| 44 |
+
|
| 45 |
**Change:** New keywords. **Rationale:** Required for new features.
|
| 46 |
|
| 47 |
- The `char8_t` keyword is added to differentiate the types of ordinary
|
| 48 |
and UTF-8 literals [[lex.string]].
|
| 49 |
- The `concept` keyword is added to enable the definition of concepts
|
|
|
|
| 63 |
not valid in this revision of C++.
|
| 64 |
|
| 65 |
**Change:** New operator `<=>`. **Rationale:** Necessary for new
|
| 66 |
functionality. **Effect on original feature:** Valid C++17 code that
|
| 67 |
contains a `<=` token immediately followed by a `>` token may be
|
| 68 |
+
ill-formed or have different semantics in this revision of C++.
|
| 69 |
+
|
| 70 |
+
[*Example 3*:
|
| 71 |
|
| 72 |
``` cpp
|
| 73 |
namespace N {
|
| 74 |
struct X {};
|
| 75 |
bool operator<=(X, X);
|
| 76 |
template<bool(X, X)> struct Y {};
|
| 77 |
Y<operator<=> y; // ill-formed; previously well-formed
|
| 78 |
}
|
| 79 |
```
|
| 80 |
|
| 81 |
+
— *end example*]
|
| 82 |
+
|
| 83 |
**Change:** Type of UTF-8 string and character literals. **Rationale:**
|
| 84 |
Required for new features. The changed types enable function
|
| 85 |
overloading, template specialization, and type deduction to distinguish
|
| 86 |
ordinary and UTF-8 string and character literals. **Effect on original
|
| 87 |
feature:** Valid C++17 code that depends on UTF-8 string literals having
|
| 88 |
type “array of `const char`” and UTF-8 character literals having type
|
| 89 |
+
“`char`” is not valid in this revision of C++.
|
| 90 |
+
|
| 91 |
+
[*Example 4*:
|
| 92 |
|
| 93 |
``` cpp
|
| 94 |
const auto *u8s = u8"text"; // u8s previously deduced as const char*; now deduced as const char8_t*
|
| 95 |
const char *ps = u8s; // ill-formed; previously well-formed
|
| 96 |
|
|
|
|
| 107 |
using type = char;
|
| 108 |
};
|
| 109 |
ct<decltype(u8'c')>::type x; // ill-formed; previously well-formed.
|
| 110 |
```
|
| 111 |
|
| 112 |
+
— *end example*]
|
| 113 |
+
|
| 114 |
### [[basic]]: basics <a id="diff.cpp17.basic">[[diff.cpp17.basic]]</a>
|
| 115 |
|
| 116 |
**Change:** A pseudo-destructor call ends the lifetime of the object to
|
| 117 |
which it is applied. **Rationale:** Increase consistency of the language
|
| 118 |
model. **Effect on original feature:** Valid ISO C++17 code may be
|
| 119 |
+
ill-formed or have undefined behavior in this revision of C++.
|
| 120 |
+
|
| 121 |
+
[*Example 1*:
|
| 122 |
|
| 123 |
``` cpp
|
| 124 |
int f() {
|
| 125 |
int a = 123;
|
| 126 |
using T = int;
|
| 127 |
a.~T();
|
| 128 |
return a; // undefined behavior; previously returned 123
|
| 129 |
}
|
| 130 |
```
|
| 131 |
|
| 132 |
+
— *end example*]
|
| 133 |
+
|
| 134 |
**Change:** Except for the initial release operation, a release sequence
|
| 135 |
consists solely of atomic read-modify-write operations. **Rationale:**
|
| 136 |
Removal of rarely used and confusing feature. **Effect on original
|
| 137 |
feature:** If a `memory_order_release` atomic store is followed by a
|
| 138 |
`memory_order_relaxed` store to the same variable by the same thread,
|
|
|
|
| 147 |
with constexpr if. **Effect on original feature:** Lambdas with a
|
| 148 |
*capture-default* may capture local entities that were not captured in
|
| 149 |
C++17 if those entities are only referenced in contexts that do not
|
| 150 |
result in an odr-use.
|
| 151 |
|
| 152 |
+
### [[dcl]]: declarations <a id="diff.cpp17.dcl.dcl">[[diff.cpp17.dcl.dcl]]</a>
|
| 153 |
|
| 154 |
**Change:** Unnamed classes with a typedef name for linkage purposes can
|
| 155 |
contain only C-compatible constructs. **Rationale:** Necessary for
|
| 156 |
implementability. **Effect on original feature:** Valid C++17 code may
|
| 157 |
+
be ill-formed in this revision of C++.
|
| 158 |
+
|
| 159 |
+
[*Example 1*:
|
| 160 |
|
| 161 |
``` cpp
|
| 162 |
typedef struct {
|
| 163 |
void f() {} // ill-formed; previously well-formed
|
| 164 |
} S;
|
| 165 |
```
|
| 166 |
|
| 167 |
+
— *end example*]
|
| 168 |
+
|
| 169 |
**Change:** A function cannot have different default arguments in
|
| 170 |
different translation units. **Rationale:** Required for modules
|
| 171 |
support. **Effect on original feature:** Valid C++17 code may be
|
| 172 |
+
ill-formed in this revision of C++, with no diagnostic required.
|
| 173 |
+
|
| 174 |
+
[*Example 2*:
|
| 175 |
|
| 176 |
``` cpp
|
| 177 |
// Translation unit 1
|
| 178 |
int f(int a = 42);
|
| 179 |
int g() { return f(); }
|
|
|
|
| 182 |
int f(int a = 76) { return a; } // ill-formed, no diagnostic required; previously well-formed
|
| 183 |
int g();
|
| 184 |
int main() { return g(); } // used to return 42
|
| 185 |
```
|
| 186 |
|
| 187 |
+
— *end example*]
|
| 188 |
+
|
| 189 |
**Change:** A class that has user-declared constructors is never an
|
| 190 |
aggregate. **Rationale:** Remove potentially error-prone aggregate
|
| 191 |
initialization which may apply notwithstanding the declared constructors
|
| 192 |
of a class. **Effect on original feature:** Valid C++17 code that
|
| 193 |
aggregate-initializes a type with a user-declared constructor may be
|
| 194 |
+
ill-formed or have different semantics in this revision of C++.
|
| 195 |
+
|
| 196 |
+
[*Example 3*:
|
| 197 |
|
| 198 |
``` cpp
|
| 199 |
struct A { // not an aggregate; previously an aggregate
|
| 200 |
A() = delete;
|
| 201 |
};
|
|
|
|
| 226 |
};
|
| 227 |
|
| 228 |
Y y{X{}}; // copy constructor call; previously aggregate-initialization
|
| 229 |
```
|
| 230 |
|
| 231 |
+
— *end example*]
|
| 232 |
+
|
| 233 |
**Change:** Boolean conversion from a pointer or pointer-to-member type
|
| 234 |
is now a narrowing conversion. **Rationale:** Catches bugs. **Effect on
|
| 235 |
original feature:** Valid C++17 code may fail to compile in this
|
| 236 |
+
revision of C++.
|
| 237 |
+
|
| 238 |
+
[*Example 4*:
|
| 239 |
|
| 240 |
``` cpp
|
| 241 |
bool y[] = { "bc" }; // ill-formed; previously well-formed
|
| 242 |
```
|
| 243 |
|
| 244 |
+
— *end example*]
|
| 245 |
+
|
| 246 |
### [[class]]: classes <a id="diff.cpp17.class">[[diff.cpp17.class]]</a>
|
| 247 |
|
| 248 |
**Change:** The class name can no longer be used parenthesized
|
| 249 |
immediately after an `explicit` *decl-specifier* in a constructor
|
| 250 |
declaration. The *conversion-function-id* can no longer be used
|
| 251 |
parenthesized immediately after an `explicit` *decl-specifier* in a
|
| 252 |
conversion function declaration. **Rationale:** Necessary for new
|
| 253 |
functionality. **Effect on original feature:** Valid C++17 code may fail
|
| 254 |
+
to compile in this revision of C++.
|
| 255 |
+
|
| 256 |
+
[*Example 1*:
|
| 257 |
|
| 258 |
``` cpp
|
| 259 |
struct S {
|
| 260 |
explicit (S)(const S&); // ill-formed; previously well-formed
|
| 261 |
explicit (operator int)(); // ill-formed; previously well-formed
|
| 262 |
explicit(true) (S)(int); // OK
|
| 263 |
};
|
| 264 |
```
|
| 265 |
|
| 266 |
+
— *end example*]
|
| 267 |
+
|
| 268 |
**Change:** A *simple-template-id* is no longer valid as the
|
| 269 |
*declarator-id* of a constructor or destructor. **Rationale:** Remove
|
| 270 |
potentially error-prone option for redundancy. **Effect on original
|
| 271 |
feature:** Valid C++17 code may fail to compile in this revision of C++.
|
| 272 |
+
|
| 273 |
+
[*Example 2*:
|
| 274 |
|
| 275 |
``` cpp
|
| 276 |
template<class T>
|
| 277 |
struct A {
|
| 278 |
A<T>(); // error: simple-template-id not allowed for constructor
|
| 279 |
A(int); // OK, injected-class-name used
|
| 280 |
~A<T>(); // error: simple-template-id not allowed for destructor
|
| 281 |
};
|
| 282 |
```
|
| 283 |
|
| 284 |
+
— *end example*]
|
| 285 |
+
|
| 286 |
**Change:** A function returning an implicitly movable entity may invoke
|
| 287 |
a constructor taking an rvalue reference to a type different from that
|
| 288 |
of the returned expression. Function and catch-clause parameters can be
|
| 289 |
thrown using move constructors. **Rationale:** Side effect of making it
|
| 290 |
easier to write more efficient code that takes advantage of moves.
|
| 291 |
**Effect on original feature:** Valid C++17 code may fail to compile or
|
| 292 |
+
have different semantics in this revision of C++.
|
| 293 |
+
|
| 294 |
+
[*Example 3*:
|
| 295 |
|
| 296 |
``` cpp
|
| 297 |
struct base {
|
| 298 |
base();
|
| 299 |
base(base const &);
|
|
|
|
| 323 |
consume(static_cast<S&&>(s));
|
| 324 |
char c = *s.m; // undefined behavior; previously ok
|
| 325 |
}
|
| 326 |
```
|
| 327 |
|
| 328 |
+
— *end example*]
|
| 329 |
+
|
| 330 |
### [[over]]: overloading <a id="diff.cpp17.over">[[diff.cpp17.over]]</a>
|
| 331 |
|
| 332 |
**Change:** Equality and inequality expressions can now find reversed
|
| 333 |
and rewritten candidates. **Rationale:** Improve consistency of equality
|
| 334 |
with three-way comparison and make it easier to write the full
|
| 335 |
complement of equality operations. **Effect on original feature:** For
|
| 336 |
certain pairs of types where one is convertible to the other, equality
|
| 337 |
or inequality expressions between an object of one type and an object of
|
| 338 |
the other type invoke a different operator. Also, for certain types,
|
| 339 |
equality or inequality expressions between two objects of that type
|
| 340 |
+
become ambiguous.
|
| 341 |
+
|
| 342 |
+
[*Example 1*:
|
| 343 |
|
| 344 |
``` cpp
|
| 345 |
struct A {
|
| 346 |
operator int() const;
|
| 347 |
};
|
|
|
|
| 355 |
(10 == x) + // calls #1, previously selected #2
|
| 356 |
(10 != x); // calls #1, previously selected #3
|
| 357 |
}
|
| 358 |
```
|
| 359 |
|
| 360 |
+
— *end example*]
|
| 361 |
+
|
| 362 |
**Change:** Overload resolution may change for equality operators
|
| 363 |
[[expr.eq]]. **Rationale:** Support calling `operator==` with reversed
|
| 364 |
order of arguments. **Effect on original feature:** Valid C++17 code
|
| 365 |
that uses equality operators with conversion functions may be ill-formed
|
| 366 |
+
or have different semantics in this revision of C++.
|
| 367 |
+
|
| 368 |
+
[*Example 2*:
|
| 369 |
|
| 370 |
``` cpp
|
| 371 |
struct A {
|
| 372 |
operator int() const { return 10; }
|
| 373 |
};
|
|
|
|
| 381 |
};
|
| 382 |
B b1;
|
| 383 |
bool eq = (b1 == b1); // ambiguous; previously well-formed
|
| 384 |
```
|
| 385 |
|
| 386 |
+
— *end example*]
|
| 387 |
+
|
| 388 |
### [[temp]]: templates <a id="diff.cpp17.temp">[[diff.cpp17.temp]]</a>
|
| 389 |
|
| 390 |
**Change:** An *unqualified-id* that is followed by a `<` and for which
|
| 391 |
name lookup finds nothing or finds a function will be treated as a
|
| 392 |
+
*template-name* in order to potentially cause argument-dependent lookup
|
| 393 |
to be performed. **Rationale:** It was problematic to call a function
|
| 394 |
+
template with an explicit template argument list via argument-dependent
|
| 395 |
lookup because of the need to have a template with the same name visible
|
| 396 |
via normal lookup. **Effect on original feature:** Previously valid code
|
| 397 |
that uses a function name as the left operand of a `<` operator would
|
| 398 |
+
become ill-formed.
|
| 399 |
+
|
| 400 |
+
[*Example 1*:
|
| 401 |
|
| 402 |
``` cpp
|
| 403 |
struct A {};
|
| 404 |
bool operator<(void (*fp)(), A);
|
| 405 |
void f() {}
|
|
|
|
| 408 |
f < a; // ill-formed; previously well-formed
|
| 409 |
(f) < a; // still well-formed
|
| 410 |
}
|
| 411 |
```
|
| 412 |
|
| 413 |
+
— *end example*]
|
| 414 |
+
|
| 415 |
### [[except]]: exception handling <a id="diff.cpp17.except">[[diff.cpp17.except]]</a>
|
| 416 |
|
| 417 |
**Change:** Remove `throw()` exception specification. **Rationale:**
|
| 418 |
Removal of obsolete feature that has been replaced by `noexcept`.
|
| 419 |
**Effect on original feature:** A valid C++17 function declaration,
|
|
|
|
| 486 |
### [[input.output]]: input/output library <a id="diff.cpp17.input.output">[[diff.cpp17.input.output]]</a>
|
| 487 |
|
| 488 |
**Change:** Character array extraction only takes array types.
|
| 489 |
**Rationale:** Increase safety via preventing buffer overflow at compile
|
| 490 |
time. **Effect on original feature:** Valid C++17 code may fail to
|
| 491 |
+
compile in this revision of C++.
|
| 492 |
+
|
| 493 |
+
[*Example 1*:
|
| 494 |
|
| 495 |
``` cpp
|
| 496 |
auto p = new char[100];
|
| 497 |
char q[100];
|
| 498 |
std::cin >> std::setw(20) >> p; // ill-formed; previously well-formed
|
| 499 |
std::cin >> std::setw(20) >> q; // OK
|
| 500 |
```
|
| 501 |
|
| 502 |
+
— *end example*]
|
| 503 |
+
|
| 504 |
**Change:** Overload resolution for ostream inserters used with UTF-8
|
| 505 |
literals. **Rationale:** Required for new features. **Effect on original
|
| 506 |
feature:** Valid C++17 code that passes UTF-8 literals to
|
| 507 |
`basic_ostream<char, ...>::operator<<` or
|
| 508 |
+
`basic_ostream<wchar_t, ...>::operator<<` is now ill-formed.
|
| 509 |
+
|
| 510 |
+
[*Example 2*:
|
| 511 |
|
| 512 |
``` cpp
|
| 513 |
std::cout << u8"text"; // previously called operator<<(const char*) and printed a string;
|
| 514 |
// now ill-formed
|
| 515 |
std::cout << u8'X'; // previously called operator<<(char) and printed a character;
|
| 516 |
// now ill-formed
|
| 517 |
```
|
| 518 |
|
| 519 |
+
— *end example*]
|
| 520 |
+
|
| 521 |
**Change:** Overload resolution for ostream inserters used with
|
| 522 |
`wchar_t`, `char16_t`, or `char32_t` types. **Rationale:** Removal of
|
| 523 |
surprising behavior. **Effect on original feature:** Valid C++17 code
|
| 524 |
that passes `wchar_t`, `char16_t`, or `char32_t` characters or strings
|
| 525 |
to `basic_ostream<char, ...>::operator<<` or that passes `char16_t` or
|
| 526 |
`char32_t` characters or strings to
|
| 527 |
+
`basic_ostream<wchar_t, ...>::operator<<` is now ill-formed.
|
| 528 |
+
|
| 529 |
+
[*Example 3*:
|
| 530 |
|
| 531 |
``` cpp
|
| 532 |
std::cout << u"text"; // previously formatted the string as a pointer value;
|
| 533 |
// now ill-formed
|
| 534 |
std::cout << u'X'; // previously formatted the character as an integer value;
|
| 535 |
// now ill-formed
|
| 536 |
```
|
| 537 |
|
| 538 |
+
— *end example*]
|
| 539 |
+
|
| 540 |
**Change:** Return type of filesystem path format observer member
|
| 541 |
functions. **Rationale:** Required for new features. **Effect on
|
| 542 |
original feature:** Valid C++17 code that depends on the `u8string()`
|
| 543 |
and `generic_u8string()` member functions of `std::filesystem::path`
|
| 544 |
+
returning `std::string` is not valid in this revision of C++.
|
| 545 |
+
|
| 546 |
+
[*Example 4*:
|
| 547 |
|
| 548 |
``` cpp
|
| 549 |
std::filesystem::path p;
|
| 550 |
std::string s1 = p.u8string(); // ill-formed; previously well-formed
|
| 551 |
std::string s2 = p.generic_u8string(); // ill-formed; previously well-formed
|
| 552 |
```
|
| 553 |
|
| 554 |
+
— *end example*]
|
| 555 |
+
|
| 556 |
### [[depr]]: compatibility features <a id="diff.cpp17.depr">[[diff.cpp17.depr]]</a>
|
| 557 |
|
| 558 |
**Change:** Remove `uncaught_exception`. **Rationale:** The function did
|
| 559 |
not have a clear specification when multiple exceptions were active, and
|
| 560 |
has been superseded by `uncaught_exceptions`. **Effect on original
|
|
|
|
| 604 |
original feature:** A valid C++17 program that calls `unique` on a
|
| 605 |
`shared_ptr` object may fail to compile.
|
| 606 |
|
| 607 |
**Change:** Remove deprecated type traits. **Rationale:** The traits had
|
| 608 |
unreliable or awkward interfaces. The `is_literal_type` trait provided
|
| 609 |
+
no way to detect which subset of member functions of a type were
|
| 610 |
+
declared `constexpr`. The `result_of` trait had a surprising syntax that
|
| 611 |
+
did not directly support function types. It has been superseded by the
|
| 612 |
+
`invoke_result` trait. **Effect on original feature:** A valid C++17
|
| 613 |
+
program that relies on the `is_literal_type` or `result_of` type traits,
|
| 614 |
+
on the `is_literal_type_v` variable template, or on the `result_of_t`
|
| 615 |
+
alias template may fail to compile.
|
| 616 |
|