Fixed by r17-2835 for PR c++/126335 and, unlike that PR's testcase, did
not depend on r17-1661 to trigger the bug.

        PR c++/126472

gcc/testsuite/ChangeLog:

        * g++.dg/cpp0x/initlist135.C: New test.
---
 gcc/testsuite/g++.dg/cpp0x/initlist135.C | 47 ++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist135.C

diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist135.C 
b/gcc/testsuite/g++.dg/cpp0x/initlist135.C
new file mode 100644
index 000000000000..759ff6833a2e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist135.C
@@ -0,0 +1,47 @@
+// PR c++/126472
+// { dg-do run { target c++11 } }
+
+namespace std {
+template <class _E> struct initializer_list {
+  typedef const _E *const_iterator;
+  const _E *_M_array;
+  unsigned long _M_len;
+  const_iterator begin() const { return _M_array; }
+  const_iterator end() const { return begin() + _M_len; }
+};
+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();
+}
-- 
2.55.0.618.g1a3e64c6c4

Reply via email to