tmp/tmp4hbs9hqa/{from.md → to.md}
RENAMED
|
@@ -1,58 +1,60 @@
|
|
| 1 |
## C++ and ISO C++11 <a id="diff.cpp11">[[diff.cpp11]]</a>
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
### [[lex]]: lexical conventions <a id="diff.cpp11.lex">[[diff.cpp11.lex]]</a>
|
| 8 |
|
| 9 |
**Change:** *pp-number* can contain one or more single quotes.
|
| 10 |
**Rationale:** Necessary to enable single quotes as digit separators.
|
| 11 |
**Effect on original feature:** Valid C++11 code may fail to compile or
|
| 12 |
-
may change meaning in this
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
``` cpp
|
| 19 |
#define M(x, ...) __VA_ARGS__
|
| 20 |
int x[2] = { M(1'2,3'4, 5) };
|
| 21 |
// int x[2] = { 5 \ \ \ \ \ } --- C++11{}
|
| 22 |
-
// int x[2] = { 3'4, 5 } --- this
|
| 23 |
```
|
| 24 |
|
| 25 |
### [[basic]]: basics <a id="diff.cpp11.basic">[[diff.cpp11.basic]]</a>
|
| 26 |
|
| 27 |
**Change:** New usual (non-placement) deallocator. **Rationale:**
|
| 28 |
Required for sized deallocation. **Effect on original feature:** Valid
|
| 29 |
-
C++11 code
|
| 30 |
deallocation function as follows:
|
| 31 |
|
| 32 |
``` cpp
|
| 33 |
void* operator new(std::size_t, std::size_t);
|
| 34 |
void operator delete(void*, std::size_t) noexcept;
|
| 35 |
```
|
| 36 |
|
| 37 |
-
In this
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
### [[expr]]: expressions <a id="diff.cpp11.expr">[[diff.cpp11.expr]]</a>
|
| 44 |
|
| 45 |
**Change:** A conditional expression with a throw expression as its
|
| 46 |
second or third operand keeps the type and value category of the other
|
| 47 |
operand. **Rationale:** Formerly mandated conversions (lvalue-to-rvalue
|
| 48 |
[[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
|
| 49 |
[[conv.func]] standard conversions), especially the creation of the
|
| 50 |
temporary due to lvalue-to-rvalue conversion, were considered gratuitous
|
| 51 |
and surprising. **Effect on original feature:** Valid C++11 code that
|
| 52 |
-
relies on the conversions may behave differently in this
|
| 53 |
-
|
| 54 |
|
| 55 |
``` cpp
|
| 56 |
struct S {
|
| 57 |
int x = 1;
|
| 58 |
void mf() { x = 2; }
|
|
@@ -62,42 +64,43 @@ int f(bool cond) {
|
|
| 62 |
(cond ? s : throw 0).mf();
|
| 63 |
return s.x;
|
| 64 |
}
|
| 65 |
```
|
| 66 |
|
| 67 |
-
In C++11, `f(true)` returns `1`. In this
|
| 68 |
-
|
| 69 |
|
| 70 |
``` cpp
|
| 71 |
sizeof(true ? "" : throw 0)
|
| 72 |
```
|
| 73 |
|
| 74 |
-
In C++11, the expression yields `sizeof(const char*)`. In this
|
| 75 |
-
|
| 76 |
|
| 77 |
### [[dcl.dcl]]: declarations <a id="diff.cpp11.dcl.dcl">[[diff.cpp11.dcl.dcl]]</a>
|
| 78 |
|
| 79 |
**Change:** `constexpr` non-static member functions are not implicitly
|
| 80 |
`const` member functions. **Rationale:** Necessary to allow `constexpr`
|
| 81 |
member functions to mutate the object. **Effect on original feature:**
|
| 82 |
-
Valid C++11 code may fail to compile in this
|
| 83 |
-
example
|
| 84 |
-
International Standard because it declares the same member function
|
| 85 |
-
twice with different return types:
|
| 86 |
|
| 87 |
``` cpp
|
| 88 |
struct S {
|
| 89 |
constexpr const int &f();
|
| 90 |
int &f();
|
| 91 |
};
|
| 92 |
```
|
| 93 |
|
|
|
|
|
|
|
|
|
|
| 94 |
**Change:** Classes with default member initializers can be aggregates.
|
| 95 |
**Rationale:** Necessary to allow default member initializers to be used
|
| 96 |
by aggregate initialization. **Effect on original feature:** Valid C++11
|
| 97 |
-
code may fail to compile or may change meaning in this
|
| 98 |
-
|
| 99 |
|
| 100 |
``` cpp
|
| 101 |
struct S { // Aggregate in C++14{} onwards.
|
| 102 |
int m = 1;
|
| 103 |
};
|
|
@@ -105,22 +108,22 @@ struct X {
|
|
| 105 |
operator int();
|
| 106 |
operator S();
|
| 107 |
};
|
| 108 |
X a{};
|
| 109 |
S b{a}; // uses copy constructor in C++11{},
|
| 110 |
-
// performs aggregate initialization in this
|
| 111 |
```
|
| 112 |
|
| 113 |
### [[library]]: library introduction <a id="diff.cpp11.library">[[diff.cpp11.library]]</a>
|
| 114 |
|
| 115 |
**Change:** New header. **Rationale:** New functionality. **Effect on
|
| 116 |
original feature:** The C++ header `<shared_mutex>` is new. Valid C++11
|
| 117 |
code that `#include`s a header with that name may be invalid in this
|
| 118 |
-
|
| 119 |
|
| 120 |
### [[input.output]]: input/output library <a id="diff.cpp11.input.output">[[diff.cpp11.input.output]]</a>
|
| 121 |
|
| 122 |
**Change:** `gets` is not defined. **Rationale:** Use of `gets` is
|
| 123 |
considered dangerous. **Effect on original feature:** Valid C++11 code
|
| 124 |
-
that uses the `gets` function may fail to compile in this
|
| 125 |
-
|
| 126 |
|
|
|
|
| 1 |
## C++ and ISO C++11 <a id="diff.cpp11">[[diff.cpp11]]</a>
|
| 2 |
|
| 3 |
+
### General <a id="diff.cpp11.general">[[diff.cpp11.general]]</a>
|
| 4 |
+
|
| 5 |
+
Subclause [[diff.cpp11]] lists the differences between C++ and ISO C++11
|
| 6 |
+
(ISO/IEC 14882:2011, *Programming Languages — C++*), in addition to
|
| 7 |
+
those listed above, by the chapters of this document.
|
| 8 |
|
| 9 |
### [[lex]]: lexical conventions <a id="diff.cpp11.lex">[[diff.cpp11.lex]]</a>
|
| 10 |
|
| 11 |
**Change:** *pp-number* can contain one or more single quotes.
|
| 12 |
**Rationale:** Necessary to enable single quotes as digit separators.
|
| 13 |
**Effect on original feature:** Valid C++11 code may fail to compile or
|
| 14 |
+
may change meaning in this revision of C++. For example, the following
|
| 15 |
+
code is valid both in C++11 and in this revision of C++, but the macro
|
| 16 |
+
invocation produces different outcomes because the single quotes delimit
|
| 17 |
+
a *character-literal* in C++11, whereas they are digit separators in
|
| 18 |
+
this revision of C++. For example:
|
| 19 |
|
| 20 |
``` cpp
|
| 21 |
#define M(x, ...) __VA_ARGS__
|
| 22 |
int x[2] = { M(1'2,3'4, 5) };
|
| 23 |
// int x[2] = { 5 \ \ \ \ \ } --- C++11{}
|
| 24 |
+
// int x[2] = { 3'4, 5 } --- this revision of C++{}
|
| 25 |
```
|
| 26 |
|
| 27 |
### [[basic]]: basics <a id="diff.cpp11.basic">[[diff.cpp11.basic]]</a>
|
| 28 |
|
| 29 |
**Change:** New usual (non-placement) deallocator. **Rationale:**
|
| 30 |
Required for sized deallocation. **Effect on original feature:** Valid
|
| 31 |
+
C++11 code can declare a global placement allocation function and
|
| 32 |
deallocation function as follows:
|
| 33 |
|
| 34 |
``` cpp
|
| 35 |
void* operator new(std::size_t, std::size_t);
|
| 36 |
void operator delete(void*, std::size_t) noexcept;
|
| 37 |
```
|
| 38 |
|
| 39 |
+
In this revision of C++, however, the declaration of `operator delete`
|
| 40 |
+
might match a predefined usual (non-placement) `operator delete`
|
| 41 |
+
[[basic.stc.dynamic]]. If so, the program is ill-formed, as it was for
|
| 42 |
+
class member allocation functions and deallocation functions
|
| 43 |
+
[[expr.new]].
|
| 44 |
|
| 45 |
### [[expr]]: expressions <a id="diff.cpp11.expr">[[diff.cpp11.expr]]</a>
|
| 46 |
|
| 47 |
**Change:** A conditional expression with a throw expression as its
|
| 48 |
second or third operand keeps the type and value category of the other
|
| 49 |
operand. **Rationale:** Formerly mandated conversions (lvalue-to-rvalue
|
| 50 |
[[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
|
| 51 |
[[conv.func]] standard conversions), especially the creation of the
|
| 52 |
temporary due to lvalue-to-rvalue conversion, were considered gratuitous
|
| 53 |
and surprising. **Effect on original feature:** Valid C++11 code that
|
| 54 |
+
relies on the conversions may behave differently in this revision of
|
| 55 |
+
C++. For example:
|
| 56 |
|
| 57 |
``` cpp
|
| 58 |
struct S {
|
| 59 |
int x = 1;
|
| 60 |
void mf() { x = 2; }
|
|
|
|
| 64 |
(cond ? s : throw 0).mf();
|
| 65 |
return s.x;
|
| 66 |
}
|
| 67 |
```
|
| 68 |
|
| 69 |
+
In C++11, `f(true)` returns `1`. In this revision of C++, it returns
|
| 70 |
+
`2`.
|
| 71 |
|
| 72 |
``` cpp
|
| 73 |
sizeof(true ? "" : throw 0)
|
| 74 |
```
|
| 75 |
|
| 76 |
+
In C++11, the expression yields `sizeof(const char*)`. In this revision
|
| 77 |
+
of C++, it yields `sizeof(const char[1])`.
|
| 78 |
|
| 79 |
### [[dcl.dcl]]: declarations <a id="diff.cpp11.dcl.dcl">[[diff.cpp11.dcl.dcl]]</a>
|
| 80 |
|
| 81 |
**Change:** `constexpr` non-static member functions are not implicitly
|
| 82 |
`const` member functions. **Rationale:** Necessary to allow `constexpr`
|
| 83 |
member functions to mutate the object. **Effect on original feature:**
|
| 84 |
+
Valid C++11 code may fail to compile in this revision of C++. For
|
| 85 |
+
example:
|
|
|
|
|
|
|
| 86 |
|
| 87 |
``` cpp
|
| 88 |
struct S {
|
| 89 |
constexpr const int &f();
|
| 90 |
int &f();
|
| 91 |
};
|
| 92 |
```
|
| 93 |
|
| 94 |
+
This code is valid in C++11 but invalid in this revision of C++ because
|
| 95 |
+
it declares the same member function twice with different return types.
|
| 96 |
+
|
| 97 |
**Change:** Classes with default member initializers can be aggregates.
|
| 98 |
**Rationale:** Necessary to allow default member initializers to be used
|
| 99 |
by aggregate initialization. **Effect on original feature:** Valid C++11
|
| 100 |
+
code may fail to compile or may change meaning in this revision of C++.
|
| 101 |
+
For example:
|
| 102 |
|
| 103 |
``` cpp
|
| 104 |
struct S { // Aggregate in C++14{} onwards.
|
| 105 |
int m = 1;
|
| 106 |
};
|
|
|
|
| 108 |
operator int();
|
| 109 |
operator S();
|
| 110 |
};
|
| 111 |
X a{};
|
| 112 |
S b{a}; // uses copy constructor in C++11{},
|
| 113 |
+
// performs aggregate initialization in this revision of C++{}
|
| 114 |
```
|
| 115 |
|
| 116 |
### [[library]]: library introduction <a id="diff.cpp11.library">[[diff.cpp11.library]]</a>
|
| 117 |
|
| 118 |
**Change:** New header. **Rationale:** New functionality. **Effect on
|
| 119 |
original feature:** The C++ header `<shared_mutex>` is new. Valid C++11
|
| 120 |
code that `#include`s a header with that name may be invalid in this
|
| 121 |
+
revision of C++.
|
| 122 |
|
| 123 |
### [[input.output]]: input/output library <a id="diff.cpp11.input.output">[[diff.cpp11.input.output]]</a>
|
| 124 |
|
| 125 |
**Change:** `gets` is not defined. **Rationale:** Use of `gets` is
|
| 126 |
considered dangerous. **Effect on original feature:** Valid C++11 code
|
| 127 |
+
that uses the `gets` function may fail to compile in this revision of
|
| 128 |
+
C++.
|
| 129 |
|