|
1 | 1 | Version 7.1 |
2 | 2 |
|
| 3 | +11/9/26 [GH #90] |
| 4 | +Constexpr reads of zero-initialized members after value initialization |
| 5 | + |
| 6 | +Value initialization of a class without a user-provided default constructor |
| 7 | +zero-initializes the object before calling the constructor. During |
| 8 | +constant evaluation, the zeroed members were not treated as initialized, so |
| 9 | +reading one that the constructor does not set was rejected. For example, |
| 10 | +with --c++20: |
| 11 | + |
| 12 | + struct A { constexpr A() {} int x; }; |
| 13 | + struct B : A { int y; }; |
| 14 | + static_assert(B().x == 0); // Previously rejected. |
| 15 | + |
| 16 | + |
| 17 | +11/9/26 [GH #90] |
| 18 | +GNU and Clang C++ modes: lifetime extension through a member of a temporary |
| 19 | + |
| 20 | +When emulating GCC 9 or later or Clang 4 or later (in C++11 and later |
| 21 | +modes), selecting a member of a class prvalue now produces an xvalue (Core |
| 22 | +issue 616), as it already did in standard C++14 and later modes. Binding a |
| 23 | +reference to the member now extends the lifetime of the whole temporary. |
| 24 | +For example, with --g++ --gnu_version=150000: |
| 25 | + |
| 26 | + struct A { int b; ~A(); }; |
| 27 | + const int &r = A().b; // A() was previously destroyed here. |
| 28 | + |
| 29 | +Returning a pointer into a member of a class prvalue is now diagnosed also |
| 30 | +when the class is trivially destructible. For example, with --c++20: |
| 31 | + |
| 32 | + struct T { int b; int arr[2]; }; |
| 33 | + T make(); |
| 34 | + const int *f() { return &make().arr[1]; } // Warning. |
| 35 | + |
| 36 | +Constant evaluation also no longer treats every member of a class prvalue |
| 37 | +as initialized when one is selected with "." or ".*". Since C++20, a |
| 38 | +constexpr constructor can leave members uninitialized, and reading such a |
| 39 | +member is now diagnosed instead of producing an indeterminate value. For |
| 40 | +example, with --c++20: |
| 41 | + |
| 42 | + struct W { int n; constexpr W() {} }; |
| 43 | + static_assert(W().n == 0); // Error: n is uninitialized. |
| 44 | + |
| 45 | +Constant evaluation now also marks each element of a GNU vector as |
| 46 | +initialized when a whole vector value is stored (e.g., by a mem-initializer), |
| 47 | +and copies the state of each element when an object containing a vector is |
| 48 | +copied. Subscripting such a vector could previously give a spurious "access |
| 49 | +to uninitialized object" error. Conversely, reading or copying a whole |
| 50 | +vector subobject now requires each of its elements to be initialized. For |
| 51 | +example, with --g++ --c++20: |
| 52 | + |
| 53 | + typedef int V4 __attribute__((vector_size(16))); |
| 54 | + struct Y { V4 v; constexpr Y(V4 a) : v(a) {} }; |
| 55 | + constexpr int f() { V4 a = {1, 2, 3, 4}; Y y(a); return y.v[3]; } |
| 56 | + static_assert(f() == 4, ""); // Previously rejected. |
| 57 | + |
| 58 | + |
| 59 | +11/9/26 [GH #491] |
| 60 | +Spurious error for pack expansions in nested generic lambdas |
| 61 | + |
| 62 | +Previously, valid pack expansions (including sizeof... and fold expressions) in |
| 63 | +nested generic lambdas (for example, in default arguments or exception |
| 64 | +specifications) could be rejected during instantiation with spurious missing |
| 65 | +parameter pack errors. For example, with --c++14 -tused: |
| 66 | + |
| 67 | + int f() { |
| 68 | + auto g = [](auto... x) { |
| 69 | + return [](auto, int n = sizeof...(x)) { return n; }(0); |
| 70 | + }; |
| 71 | + return g(1, 2); // Previously a spurious error, now okay. |
| 72 | + } |
| 73 | + |
| 74 | + |
3 | 75 | 11/6/26 [GH #370] |
4 | 76 | C++26: comparison between two arrays is not allowed |
5 | 77 |
|
|
0 commit comments