https://gcc.gnu.org/g:4e5dbaada9e2cf4798f48dd1bb9d0ec8927a9509

commit r16-9628-g4e5dbaada9e2cf4798f48dd1bb9d0ec8927a9509
Author: Patrick Palka <[email protected]>
Date:   Fri Aug 21 08:16:29 2026 -0400

    c++: add fixed test [PR126472]
    
    Fixed by r17-2835 for PR c++/126335.  Unlike that PR's testcase, this
    testcase does not depend on r17-1661 to trigger the latent bug.
    
    [ Squashed with r17-3485-g2bb0802bf84491. ]
    
            PR c++/126472
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/initlist135.C: New test.
    
    (cherry picked from commit 222f7f90191563a71dfbc710c8de950ace91c439)

Diff:
---
 gcc/testsuite/g++.dg/cpp0x/initlist135.C | 42 ++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist135.C 
b/gcc/testsuite/g++.dg/cpp0x/initlist135.C
new file mode 100644
index 000000000000..8dda882f8d5d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist135.C
@@ -0,0 +1,42 @@
+// PR c++/126472
+// { dg-do run { target c++11 } }
+
+#include <initializer_list>
+
+namespace std {
+struct _Optional_payload_base {
+  struct _Storage {
+    constexpr _Storage() : _M_empty() {}
+#if __cpp_constexpr >= 201907L
+    constexpr
+#endif
+    ~_Storage() {}
+    int _M_empty;
+  } _M_payload;
+};
+struct _Optional_payload : _Optional_payload_base {};
+template <typename> struct optional {
+  constexpr optional() {}
+  template <typename _Up> optional(_Up) {}
+  _Optional_payload _M_payload;
+};
+template <typename _T1, typename _T2> struct pair {
+  _T1 first;
+  _T2 second;
+  constexpr pair(_T1 __x, _T2 __y) : first(__x), second(__y) { }
+};
+template <typename> struct vector {
+  vector(int, int) {}
+};
+} // namespace std
+
+using namespace std;
+const initializer_list<pair<optional<vector<int>>, int>> data {
+  pair<optional<vector<int>>, int>( optional<vector<int>>(vector<int>(1, 10)), 
42), // non-constant
+  pair<optional<vector<int>>, int>( optional<vector<int>>(), 100), // constant
+};
+
+int main() {
+  if (data.begin()[0].second != 42 || data.begin()[1].second != 100)
+    __builtin_abort();
+}

Reply via email to