[Bug c++/126472] Wrong initialization (zero-initialization) in initializer_list

"ppalka at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126472

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org
           Keywords|needs-bisection             |
   Last reconfirmed|                            |2026-07-29
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
          Component|libstdc++                   |c++
            Summary|[13/14/15/16 regression]    |Wrong initialization
                   |Wrong initialization        |(zero-initialization) in
                   |(zero-initialization) in    |initializer_list
                   |initializer_list            |

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Sam James from comment #1)
> It starts with GCC 11. Using preprocessed source from GCC 10 works, so
> library bug probably.
GCC 11.1 and 11.2 preprocessed soruces work for me, 11.3 doesn't. I thought
it's a library bug too but after some reducing it seems an std::optional
constexpr refactoring/enablement library patch is exposing a non-regression
front end bug.  Reduced:

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() {}
    constexpr ~_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();
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.