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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## C++ and ISO C++17 <a id="diff.cpp17">[[diff.cpp17]]</a>
|
| 2 |
+
|
| 3 |
+
This subclause lists the differences between C++ and ISO C++17 (ISO/IEC
|
| 4 |
+
14882:2017, *Programming Languages — C++*), by the chapters of this
|
| 5 |
+
document.
|
| 6 |
+
|
| 7 |
+
### [[lex]]: lexical conventions <a id="diff.cpp17.lex">[[diff.cpp17.lex]]</a>
|
| 8 |
+
|
| 9 |
+
**Change:** New identifiers with special meaning. **Rationale:**
|
| 10 |
+
Required for new features. **Effect on original feature:** Logical lines
|
| 11 |
+
beginning with `module` or `import` may be interpreted differently in
|
| 12 |
+
this International Standard.
|
| 13 |
+
|
| 14 |
+
[*Example 1*:
|
| 15 |
+
|
| 16 |
+
``` cpp
|
| 17 |
+
class module {};
|
| 18 |
+
module m1; // was variable declaration; now module-declaration
|
| 19 |
+
module *m2; // variable declaration
|
| 20 |
+
|
| 21 |
+
class import {};
|
| 22 |
+
import j1; // was variable declaration; now import-declaration
|
| 23 |
+
::import j2; // variable declaration
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
— *end example*]
|
| 27 |
+
|
| 28 |
+
**Change:** *header-name* tokens are formed in more contexts.
|
| 29 |
+
**Rationale:** Required for new features. **Effect on original
|
| 30 |
+
feature:** When the identifier `import` is followed by a `<` character,
|
| 31 |
+
a *header-name* token may be formed.
|
| 32 |
+
|
| 33 |
+
[*Example 2*:
|
| 34 |
+
|
| 35 |
+
``` cpp
|
| 36 |
+
template<typename> class import {};
|
| 37 |
+
import<int> f(); // ill-formed; previously well-formed
|
| 38 |
+
::import<int> g(); // OK
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
— *end example*]
|
| 42 |
+
|
| 43 |
+
**Change:** New keywords. **Rationale:** Required for new features.
|
| 44 |
+
|
| 45 |
+
- The `char8_t` keyword is added to differentiate the types of ordinary
|
| 46 |
+
and UTF-8 literals [[lex.string]].
|
| 47 |
+
- The `concept` keyword is added to enable the definition of concepts
|
| 48 |
+
[[temp.concept]].
|
| 49 |
+
- The `consteval` keyword is added to declare immediate functions
|
| 50 |
+
[[dcl.constexpr]].
|
| 51 |
+
- The `constinit` keyword is added to prevent unintended dynamic
|
| 52 |
+
initialization [[dcl.constinit]].
|
| 53 |
+
- The `co_await`, `co_yield`, and `co_return` keywords are added to
|
| 54 |
+
enable the definition of coroutines [[dcl.fct.def.coroutine]].
|
| 55 |
+
- The `requires` keyword is added to introduce constraints through a
|
| 56 |
+
*requires-clause* [[temp.pre]] or a *requires-expression*
|
| 57 |
+
[[expr.prim.req]].
|
| 58 |
+
|
| 59 |
+
Valid C++17 code using `char8_t`, `concept`, `consteval`, `constinit`,
|
| 60 |
+
`co_await`, `co_yield`, `co_return`, or `requires` as an identifier is
|
| 61 |
+
not valid in this International Standard.
|
| 62 |
+
|
| 63 |
+
**Change:** New operator `<=>`. **Rationale:** Necessary for new
|
| 64 |
+
functionality. **Effect on original feature:** Valid C++17 code that
|
| 65 |
+
contains a `<=` token immediately followed by a `>` token may be
|
| 66 |
+
ill-formed or have different semantics in this International Standard:
|
| 67 |
+
|
| 68 |
+
``` cpp
|
| 69 |
+
namespace N {
|
| 70 |
+
struct X {};
|
| 71 |
+
bool operator<=(X, X);
|
| 72 |
+
template<bool(X, X)> struct Y {};
|
| 73 |
+
Y<operator<=> y; // ill-formed; previously well-formed
|
| 74 |
+
}
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
**Change:** Type of UTF-8 string and character literals. **Rationale:**
|
| 78 |
+
Required for new features. The changed types enable function
|
| 79 |
+
overloading, template specialization, and type deduction to distinguish
|
| 80 |
+
ordinary and UTF-8 string and character literals. **Effect on original
|
| 81 |
+
feature:** Valid C++17 code that depends on UTF-8 string literals having
|
| 82 |
+
type “array of `const char`” and UTF-8 character literals having type
|
| 83 |
+
“`char`” is not valid in this International Standard.
|
| 84 |
+
|
| 85 |
+
``` cpp
|
| 86 |
+
const auto *u8s = u8"text"; // u8s previously deduced as const char*; now deduced as const char8_t*
|
| 87 |
+
const char *ps = u8s; // ill-formed; previously well-formed
|
| 88 |
+
|
| 89 |
+
auto u8c = u8'c'; // u8c previously deduced as char; now deduced as char8_t
|
| 90 |
+
char *pc = &u8c; // ill-formed; previously well-formed
|
| 91 |
+
|
| 92 |
+
std::string s = u8"text"; // ill-formed; previously well-formed
|
| 93 |
+
|
| 94 |
+
void f(const char *s);
|
| 95 |
+
f(u8"text"); // ill-formed; previously well-formed
|
| 96 |
+
|
| 97 |
+
template<typename> struct ct;
|
| 98 |
+
template<> struct ct<char> {
|
| 99 |
+
using type = char;
|
| 100 |
+
};
|
| 101 |
+
ct<decltype(u8'c')>::type x; // ill-formed; previously well-formed.
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
### [[basic]]: basics <a id="diff.cpp17.basic">[[diff.cpp17.basic]]</a>
|
| 105 |
+
|
| 106 |
+
**Change:** A pseudo-destructor call ends the lifetime of the object to
|
| 107 |
+
which it is applied. **Rationale:** Increase consistency of the language
|
| 108 |
+
model. **Effect on original feature:** Valid ISO C++17 code may be
|
| 109 |
+
ill-formed or have undefined behavior in this International Standard.
|
| 110 |
+
|
| 111 |
+
[*Example 1*:
|
| 112 |
+
|
| 113 |
+
``` cpp
|
| 114 |
+
int f() {
|
| 115 |
+
int a = 123;
|
| 116 |
+
using T = int;
|
| 117 |
+
a.~T();
|
| 118 |
+
return a; // undefined behavior; previously returned 123
|
| 119 |
+
}
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
— *end example*]
|
| 123 |
+
|
| 124 |
+
**Change:** Except for the initial release operation, a release sequence
|
| 125 |
+
consists solely of atomic read-modify-write operations. **Rationale:**
|
| 126 |
+
Removal of rarely used and confusing feature. **Effect on original
|
| 127 |
+
feature:** If a `memory_order_release` atomic store is followed by a
|
| 128 |
+
`memory_order_relaxed` store to the same variable by the same thread,
|
| 129 |
+
then reading the latter value with a `memory_order_acquire` load no
|
| 130 |
+
longer provides any “happens before” guarantees, even in the absence of
|
| 131 |
+
intervening stores by another thread.
|
| 132 |
+
|
| 133 |
+
### [[expr]]: expressions <a id="diff.cpp17.expr">[[diff.cpp17.expr]]</a>
|
| 134 |
+
|
| 135 |
+
**Change:** Implicit lambda capture may capture additional entities.
|
| 136 |
+
**Rationale:** Rule simplification, necessary to resolve interactions
|
| 137 |
+
with constexpr if. **Effect on original feature:** Lambdas with a
|
| 138 |
+
*capture-default* may capture local entities that were not captured in
|
| 139 |
+
C++17 if those entities are only referenced in contexts that do not
|
| 140 |
+
result in an odr-use.
|
| 141 |
+
|
| 142 |
+
### [[dcl.dcl]]: declarations <a id="diff.cpp17.dcl.dcl">[[diff.cpp17.dcl.dcl]]</a>
|
| 143 |
+
|
| 144 |
+
**Change:** Unnamed classes with a typedef name for linkage purposes can
|
| 145 |
+
contain only C-compatible constructs. **Rationale:** Necessary for
|
| 146 |
+
implementability. **Effect on original feature:** Valid C++17 code may
|
| 147 |
+
be ill-formed in this International Standard.
|
| 148 |
+
|
| 149 |
+
``` cpp
|
| 150 |
+
typedef struct {
|
| 151 |
+
void f() {} // ill-formed; previously well-formed
|
| 152 |
+
} S;
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
**Change:** A function cannot have different default arguments in
|
| 156 |
+
different translation units. **Rationale:** Required for modules
|
| 157 |
+
support. **Effect on original feature:** Valid C++17 code may be
|
| 158 |
+
ill-formed in this International Standard, with no diagnostic required.
|
| 159 |
+
|
| 160 |
+
``` cpp
|
| 161 |
+
// Translation unit 1
|
| 162 |
+
int f(int a = 42);
|
| 163 |
+
int g() { return f(); }
|
| 164 |
+
|
| 165 |
+
// Translation unit 2
|
| 166 |
+
int f(int a = 76) { return a; } // ill-formed, no diagnostic required; previously well-formed
|
| 167 |
+
int g();
|
| 168 |
+
int main() { return g(); } // used to return 42
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
**Change:** A class that has user-declared constructors is never an
|
| 172 |
+
aggregate. **Rationale:** Remove potentially error-prone aggregate
|
| 173 |
+
initialization which may apply notwithstanding the declared constructors
|
| 174 |
+
of a class. **Effect on original feature:** Valid C++17 code that
|
| 175 |
+
aggregate-initializes a type with a user-declared constructor may be
|
| 176 |
+
ill-formed or have different semantics in this International Standard.
|
| 177 |
+
|
| 178 |
+
``` cpp
|
| 179 |
+
struct A { // not an aggregate; previously an aggregate
|
| 180 |
+
A() = delete;
|
| 181 |
+
};
|
| 182 |
+
|
| 183 |
+
struct B { // not an aggregate; previously an aggregate
|
| 184 |
+
B() = default;
|
| 185 |
+
int i = 0;
|
| 186 |
+
};
|
| 187 |
+
|
| 188 |
+
struct C { // not an aggregate; previously an aggregate
|
| 189 |
+
C(C&&) = default;
|
| 190 |
+
int a, b;
|
| 191 |
+
};
|
| 192 |
+
|
| 193 |
+
A a{}; // ill-formed; previously well-formed
|
| 194 |
+
B b = {1}; // ill-formed; previously well-formed
|
| 195 |
+
auto* c = new C{2, 3}; // ill-formed; previously well-formed
|
| 196 |
+
|
| 197 |
+
struct Y;
|
| 198 |
+
|
| 199 |
+
struct X {
|
| 200 |
+
operator Y();
|
| 201 |
+
};
|
| 202 |
+
|
| 203 |
+
struct Y { // not an aggregate; previously an aggregate
|
| 204 |
+
Y(const Y&) = default;
|
| 205 |
+
X x;
|
| 206 |
+
};
|
| 207 |
+
|
| 208 |
+
Y y{X{}}; // copy constructor call; previously aggregate-initialization
|
| 209 |
+
```
|
| 210 |
+
|
| 211 |
+
**Change:** Boolean conversion from a pointer or pointer-to-member type
|
| 212 |
+
is now a narrowing conversion. **Rationale:** Catches bugs. **Effect on
|
| 213 |
+
original feature:** Valid C++17 code may fail to compile in this
|
| 214 |
+
International Standard. For example:
|
| 215 |
+
|
| 216 |
+
``` cpp
|
| 217 |
+
bool y[] = { "bc" }; // ill-formed; previously well-formed
|
| 218 |
+
```
|
| 219 |
+
|
| 220 |
+
### [[class]]: classes <a id="diff.cpp17.class">[[diff.cpp17.class]]</a>
|
| 221 |
+
|
| 222 |
+
**Change:** The class name can no longer be used parenthesized
|
| 223 |
+
immediately after an `explicit` *decl-specifier* in a constructor
|
| 224 |
+
declaration. The *conversion-function-id* can no longer be used
|
| 225 |
+
parenthesized immediately after an `explicit` *decl-specifier* in a
|
| 226 |
+
conversion function declaration. **Rationale:** Necessary for new
|
| 227 |
+
functionality. **Effect on original feature:** Valid C++17 code may fail
|
| 228 |
+
to compile in this International Standard. For example:
|
| 229 |
+
|
| 230 |
+
``` cpp
|
| 231 |
+
struct S {
|
| 232 |
+
explicit (S)(const S&); // ill-formed; previously well-formed
|
| 233 |
+
explicit (operator int)(); // ill-formed; previously well-formed
|
| 234 |
+
explicit(true) (S)(int); // OK
|
| 235 |
+
};
|
| 236 |
+
```
|
| 237 |
+
|
| 238 |
+
**Change:** A *simple-template-id* is no longer valid as the
|
| 239 |
+
*declarator-id* of a constructor or destructor. **Rationale:** Remove
|
| 240 |
+
potentially error-prone option for redundancy. **Effect on original
|
| 241 |
+
feature:** Valid C++17 code may fail to compile in this International
|
| 242 |
+
Standard. For example:
|
| 243 |
+
|
| 244 |
+
``` cpp
|
| 245 |
+
template<class T>
|
| 246 |
+
struct A {
|
| 247 |
+
A<T>(); // error: simple-template-id not allowed for constructor
|
| 248 |
+
A(int); // OK, injected-class-name used
|
| 249 |
+
~A<T>(); // error: simple-template-id not allowed for destructor
|
| 250 |
+
};
|
| 251 |
+
```
|
| 252 |
+
|
| 253 |
+
**Change:** A function returning an implicitly movable entity may invoke
|
| 254 |
+
a constructor taking an rvalue reference to a type different from that
|
| 255 |
+
of the returned expression. Function and catch-clause parameters can be
|
| 256 |
+
thrown using move constructors. **Rationale:** Side effect of making it
|
| 257 |
+
easier to write more efficient code that takes advantage of moves.
|
| 258 |
+
**Effect on original feature:** Valid C++17 code may fail to compile or
|
| 259 |
+
have different semantics in this International Standard. For example:
|
| 260 |
+
|
| 261 |
+
``` cpp
|
| 262 |
+
struct base {
|
| 263 |
+
base();
|
| 264 |
+
base(base const &);
|
| 265 |
+
private:
|
| 266 |
+
base(base &&);
|
| 267 |
+
};
|
| 268 |
+
|
| 269 |
+
struct derived : base {};
|
| 270 |
+
|
| 271 |
+
base f(base b) {
|
| 272 |
+
throw b; // error: base(base &&) is private
|
| 273 |
+
derived d;
|
| 274 |
+
return d; // error: base(base &&) is private
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
struct S {
|
| 278 |
+
S(const char *s) : m(s) { }
|
| 279 |
+
S(const S&) = default;
|
| 280 |
+
S(S&& other) : m(other.m) { other.m = nullptr; }
|
| 281 |
+
const char * m;
|
| 282 |
+
};
|
| 283 |
+
|
| 284 |
+
S consume(S&& s) { return s; }
|
| 285 |
+
|
| 286 |
+
void g() {
|
| 287 |
+
S s("text");
|
| 288 |
+
consume(static_cast<S&&>(s));
|
| 289 |
+
char c = *s.m; // undefined behavior; previously ok
|
| 290 |
+
}
|
| 291 |
+
```
|
| 292 |
+
|
| 293 |
+
### [[over]]: overloading <a id="diff.cpp17.over">[[diff.cpp17.over]]</a>
|
| 294 |
+
|
| 295 |
+
**Change:** Equality and inequality expressions can now find reversed
|
| 296 |
+
and rewritten candidates. **Rationale:** Improve consistency of equality
|
| 297 |
+
with three-way comparison and make it easier to write the full
|
| 298 |
+
complement of equality operations. **Effect on original feature:**
|
| 299 |
+
Equality and inequality expressions between two objects of different
|
| 300 |
+
types, where one is convertible to the other, could invoke a different
|
| 301 |
+
operator. Equality and inequality expressions between two objects of the
|
| 302 |
+
same type could become ambiguous.
|
| 303 |
+
|
| 304 |
+
``` cpp
|
| 305 |
+
struct A {
|
| 306 |
+
operator int() const;
|
| 307 |
+
};
|
| 308 |
+
|
| 309 |
+
bool operator==(A, int); // #1
|
| 310 |
+
// #2 is built-in candidate: bool operator==(int, int);
|
| 311 |
+
// #3 is built-in candidate: bool operator!=(int, int);
|
| 312 |
+
|
| 313 |
+
int check(A x, A y) {
|
| 314 |
+
return (x == y) + // ill-formed; previously well-formed
|
| 315 |
+
(10 == x) + // calls #1, previously selected #2
|
| 316 |
+
(10 != x); // calls #1, previously selected #3
|
| 317 |
+
}
|
| 318 |
+
```
|
| 319 |
+
|
| 320 |
+
### [[temp]]: templates <a id="diff.cpp17.temp">[[diff.cpp17.temp]]</a>
|
| 321 |
+
|
| 322 |
+
**Change:** An *unqualified-id* that is followed by a `<` and for which
|
| 323 |
+
name lookup finds nothing or finds a function will be treated as a
|
| 324 |
+
*template-name* in order to potentially cause argument dependent lookup
|
| 325 |
+
to be performed. **Rationale:** It was problematic to call a function
|
| 326 |
+
template with an explicit template argument list via argument dependent
|
| 327 |
+
lookup because of the need to have a template with the same name visible
|
| 328 |
+
via normal lookup. **Effect on original feature:** Previously valid code
|
| 329 |
+
that uses a function name as the left operand of a `<` operator would
|
| 330 |
+
become ill-formed.
|
| 331 |
+
|
| 332 |
+
``` cpp
|
| 333 |
+
struct A {};
|
| 334 |
+
bool operator<(void (*fp)(), A);
|
| 335 |
+
void f() {}
|
| 336 |
+
int main() {
|
| 337 |
+
A a;
|
| 338 |
+
f < a; // ill-formed; previously well-formed
|
| 339 |
+
(f) < a; // still well formed
|
| 340 |
+
}
|
| 341 |
+
```
|
| 342 |
+
|
| 343 |
+
### [[except]]: exception handling <a id="diff.cpp17.except">[[diff.cpp17.except]]</a>
|
| 344 |
+
|
| 345 |
+
**Change:** Remove `throw()` exception specification. **Rationale:**
|
| 346 |
+
Removal of obsolete feature that has been replaced by `noexcept`.
|
| 347 |
+
**Effect on original feature:** A valid C++17 function declaration,
|
| 348 |
+
member function declaration, function pointer declaration, or function
|
| 349 |
+
reference declaration that uses `throw()` for its exception
|
| 350 |
+
specification will be rejected as ill-formed in this International
|
| 351 |
+
Standard. It should simply be replaced with `noexcept` for no change of
|
| 352 |
+
meaning since C++17.
|
| 353 |
+
|
| 354 |
+
[*Note 1*: There is no way to write a function declaration that is
|
| 355 |
+
non-throwing in this International Standard and is also non-throwing in
|
| 356 |
+
C++03 except by using the preprocessor to generate a different token
|
| 357 |
+
sequence in each case. — *end note*]
|
| 358 |
+
|
| 359 |
+
### [[library]]: library introduction <a id="diff.cpp17.library">[[diff.cpp17.library]]</a>
|
| 360 |
+
|
| 361 |
+
**Change:** New headers. **Rationale:** New functionality. **Effect on
|
| 362 |
+
original feature:** The following C++ headers are new: `<barrier>`,
|
| 363 |
+
`<bit>`, `<charconv>`, `<compare>`, `<concepts>`, `<coroutine>`,
|
| 364 |
+
`<format>`, `<latch>`, `<numbers>`, `<ranges>`, `<semaphore>`,
|
| 365 |
+
`<source_location>`, `<span>`, `<stop_token>`, `<syncstream>`, and
|
| 366 |
+
`<version>`. Valid C++17 code that `#include`s headers with these names
|
| 367 |
+
may be invalid in this International Standard.
|
| 368 |
+
|
| 369 |
+
**Change:** Remove vacuous C++ header files. **Rationale:** The empty
|
| 370 |
+
headers implied a false requirement to achieve C compatibility with the
|
| 371 |
+
C++ headers. **Effect on original feature:** A valid C++17 program that
|
| 372 |
+
`#include`s any of the following headers may fail to compile:
|
| 373 |
+
`<ccomplex>`, `<ciso646>`, `<cstdalign>`, `<cstdbool>`, and `<ctgmath>`.
|
| 374 |
+
To retain the same behavior:
|
| 375 |
+
|
| 376 |
+
- a `#include` of `<ccomplex>` can be replaced by a `#include` of
|
| 377 |
+
`<complex>`,
|
| 378 |
+
- a `#include` of `<ctgmath>` can be replaced by a `#include` of
|
| 379 |
+
`<cmath>` and a `#include` of `<complex>`, and
|
| 380 |
+
- a `#include` of `<ciso646>`, `<cstdalign>`, or `<cstdbool>` can simply
|
| 381 |
+
be removed.
|
| 382 |
+
|
| 383 |
+
### [[containers]]: containers library <a id="diff.cpp17.containers">[[diff.cpp17.containers]]</a>
|
| 384 |
+
|
| 385 |
+
**Change:** Return types of `remove`, `remove_if`, and `unique` changed
|
| 386 |
+
from `void` to `container::size_type`. **Rationale:** Improve efficiency
|
| 387 |
+
and convenience of finding number of removed elements. **Effect on
|
| 388 |
+
original feature:** Code that depends on the return types might have
|
| 389 |
+
different semantics in this International Standard. Translation units
|
| 390 |
+
compiled against this version of C++ may be incompatible with
|
| 391 |
+
translation units compiled against C++17, either failing to link or
|
| 392 |
+
having undefined behavior.
|
| 393 |
+
|
| 394 |
+
### [[iterators]]: iterators library <a id="diff.cpp17.iterators">[[diff.cpp17.iterators]]</a>
|
| 395 |
+
|
| 396 |
+
**Change:** The specialization of `iterator_traits` for `void*` and for
|
| 397 |
+
function pointer types no longer contains any nested typedefs.
|
| 398 |
+
**Rationale:** Corrects an issue misidentifying pointer types that are
|
| 399 |
+
not incrementable as iterator types. **Effect on original feature:** A
|
| 400 |
+
valid C++17 program that relies on the presence of the typedefs may fail
|
| 401 |
+
to compile, or have different behavior.
|
| 402 |
+
|
| 403 |
+
### [[algorithms]]: algorithms library <a id="diff.cpp17.alg.reqs">[[diff.cpp17.alg.reqs]]</a>
|
| 404 |
+
|
| 405 |
+
**Change:** The number and order of deducible template parameters for
|
| 406 |
+
algorithm declarations is now unspecified, instead of being as-declared.
|
| 407 |
+
**Rationale:** Increase implementor freedom and allow some function
|
| 408 |
+
templates to be implemented as function objects with templated call
|
| 409 |
+
operators. **Effect on original feature:** A valid C++17 program that
|
| 410 |
+
passes explicit template arguments to algorithms not explicitly
|
| 411 |
+
specified to allow such in this version of C++ may fail to compile or
|
| 412 |
+
have undefined behavior.
|
| 413 |
+
|
| 414 |
+
### [[input.output]]: input/output library <a id="diff.cpp17.input.output">[[diff.cpp17.input.output]]</a>
|
| 415 |
+
|
| 416 |
+
**Change:** Character array extraction only takes array types.
|
| 417 |
+
**Rationale:** Increase safety via preventing buffer overflow at compile
|
| 418 |
+
time. **Effect on original feature:** Valid C++17 code may fail to
|
| 419 |
+
compile in this International Standard:
|
| 420 |
+
|
| 421 |
+
``` cpp
|
| 422 |
+
auto p = new char[100];
|
| 423 |
+
char q[100];
|
| 424 |
+
std::cin >> std::setw(20) >> p; // ill-formed; previously well-formed
|
| 425 |
+
std::cin >> std::setw(20) >> q; // OK
|
| 426 |
+
```
|
| 427 |
+
|
| 428 |
+
**Change:** Overload resolution for ostream inserters used with UTF-8
|
| 429 |
+
literals. **Rationale:** Required for new features. **Effect on original
|
| 430 |
+
feature:** Valid C++17 code that passes UTF-8 literals to
|
| 431 |
+
`basic_ostream<char, ...>::operator<<` or
|
| 432 |
+
`basic_ostream<wchar_t, ...>::operator<<` is now ill-formed.
|
| 433 |
+
|
| 434 |
+
``` cpp
|
| 435 |
+
std::cout << u8"text"; // previously called operator<<(const char*) and printed a string;
|
| 436 |
+
// now ill-formed
|
| 437 |
+
std::cout << u8'X'; // previously called operator<<(char) and printed a character;
|
| 438 |
+
// now ill-formed
|
| 439 |
+
```
|
| 440 |
+
|
| 441 |
+
**Change:** Overload resolution for ostream inserters used with
|
| 442 |
+
`wchar_t`, `char16_t`, or `char32_t` types. **Rationale:** Removal of
|
| 443 |
+
surprising behavior. **Effect on original feature:** Valid C++17 code
|
| 444 |
+
that passes `wchar_t`, `char16_t`, or `char32_t` characters or strings
|
| 445 |
+
to `basic_ostream<char, ...>::operator<<` or that passes `char16_t` or
|
| 446 |
+
`char32_t` characters or strings to
|
| 447 |
+
`basic_ostream<wchar_t, ...>::operator<<` is now ill-formed.
|
| 448 |
+
|
| 449 |
+
``` cpp
|
| 450 |
+
std::cout << u"text"; // previously formatted the string as a pointer value;
|
| 451 |
+
// now ill-formed
|
| 452 |
+
std::cout << u'X'; // previously formatted the character as an integer value;
|
| 453 |
+
// now ill-formed
|
| 454 |
+
```
|
| 455 |
+
|
| 456 |
+
**Change:** Return type of filesystem path format observer member
|
| 457 |
+
functions. **Rationale:** Required for new features. **Effect on
|
| 458 |
+
original feature:** Valid C++17 code that depends on the `u8string()`
|
| 459 |
+
and `generic_u8string()` member functions of `std::filesystem::path`
|
| 460 |
+
returning `std::string` is not valid in this International Standard.
|
| 461 |
+
|
| 462 |
+
``` cpp
|
| 463 |
+
std::filesystem::path p;
|
| 464 |
+
std::string s1 = p.u8string(); // ill-formed; previously well-formed
|
| 465 |
+
std::string s2 = p.generic_u8string(); // ill-formed; previously well-formed
|
| 466 |
+
```
|
| 467 |
+
|
| 468 |
+
### [[depr]]: compatibility features <a id="diff.cpp17.depr">[[diff.cpp17.depr]]</a>
|
| 469 |
+
|
| 470 |
+
**Change:** Remove `uncaught_exception`. **Rationale:** The function did
|
| 471 |
+
not have a clear specification when multiple exceptions were active, and
|
| 472 |
+
has been superseded by `uncaught_exceptions`. **Effect on original
|
| 473 |
+
feature:** A valid C++17 program that calls `std::uncaught_exception`
|
| 474 |
+
may fail to compile. It might be revised to use
|
| 475 |
+
`std::uncaught_exceptions` instead, for clear and portable semantics.
|
| 476 |
+
|
| 477 |
+
**Change:** Remove support for adaptable function API. **Rationale:**
|
| 478 |
+
The deprecated support relied on a limited convention that could not be
|
| 479 |
+
extended to support the general case or new language features. It has
|
| 480 |
+
been superseded by direct language support with `decltype`, and by the
|
| 481 |
+
`std::bind` and `std::not_fn` function templates. **Effect on original
|
| 482 |
+
feature:** A valid C++17 program that relies on the presence of
|
| 483 |
+
`result_type`, `argument_type`, `first_argument_type`, or
|
| 484 |
+
`second_argument_type` in a standard library class may fail to compile.
|
| 485 |
+
A valid C++17 program that calls `not1` or `not2`, or uses the class
|
| 486 |
+
templates `unary_negate` or `binary_negate`, may fail to compile.
|
| 487 |
+
|
| 488 |
+
**Change:** Remove redundant members from `std::allocator`.
|
| 489 |
+
**Rationale:** `std::allocator` was overspecified, encouraging direct
|
| 490 |
+
usage in user containers rather than relying on `std::allocator_traits`,
|
| 491 |
+
leading to poor containers. **Effect on original feature:** A valid
|
| 492 |
+
C++17 program that directly makes use of the `pointer`, `const_pointer`,
|
| 493 |
+
`reference`, `const_reference`, `rebind`, `address`, `construct`,
|
| 494 |
+
`destroy`, or `max_size` members of `std::allocator`, or that directly
|
| 495 |
+
calls `allocate` with an additional hint argument, may fail to compile.
|
| 496 |
+
|
| 497 |
+
**Change:** Remove `raw_storage_iterator`. **Rationale:** The iterator
|
| 498 |
+
encouraged use of algorithms that might throw exceptions, but did not
|
| 499 |
+
return the number of elements successfully constructed that might need
|
| 500 |
+
to be destroyed in order to avoid leaks. **Effect on original feature:**
|
| 501 |
+
A valid C++17 program that uses this iterator class may fail to compile.
|
| 502 |
+
|
| 503 |
+
**Change:** Remove temporary buffers API. **Rationale:** The temporary
|
| 504 |
+
buffer facility was intended to provide an efficient optimization for
|
| 505 |
+
small memory requests, but there is little evidence this was achieved in
|
| 506 |
+
practice, while requiring the user to provide their own exception-safe
|
| 507 |
+
wrappers to guard use of the facility in many cases. **Effect on
|
| 508 |
+
original feature:** A valid C++17 program that calls
|
| 509 |
+
`get_temporary_buffer` or `return_temporary_buffer` may fail to compile.
|
| 510 |
+
|
| 511 |
+
**Change:** Remove `shared_ptr::unique`. **Rationale:** The result of a
|
| 512 |
+
call to this member function is not reliable in the presence of multiple
|
| 513 |
+
threads and weak pointers. The member function `use_count` is similarly
|
| 514 |
+
unreliable, but has a clearer contract in such cases, and remains
|
| 515 |
+
available for well defined use in single-threaded cases. **Effect on
|
| 516 |
+
original feature:** A valid C++17 program that calls `unique` on a
|
| 517 |
+
`shared_ptr` object may fail to compile.
|
| 518 |
+
|
| 519 |
+
**Change:** Remove deprecated type traits. **Rationale:** The traits had
|
| 520 |
+
unreliable or awkward interfaces. The `is_literal_type` trait provided
|
| 521 |
+
no way to detect which subset of constructors and member functions of a
|
| 522 |
+
type were declared `constexpr`. The `result_of` trait had a surprising
|
| 523 |
+
syntax that could not report the result of a regular function type. It
|
| 524 |
+
has been superseded by the `invoke_result` trait. **Effect on original
|
| 525 |
+
feature:** A valid C++17 program that relies on the `is_literal_type` or
|
| 526 |
+
`result_of` type traits, on the `is_literal_type_v` variable template,
|
| 527 |
+
or on the `result_of_t` alias template may fail to compile.
|
| 528 |
+
|