https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108309
Bug ID: 108309 Summary: ICE in in cxx_eval_component_reference, at cp/constexpr.cc:4136 Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: tim at klingt dot org Target Milestone: --- ``` template <typename _Tp> constexpr _Tp forward(_Tp &__t) { return static_cast<_Tp &&>(__t); } struct _Enable_copy_move {}; struct optional; template <int _Nm> struct __array_traits { typedef optional _Type[_Nm]; }; template <int _Nm> struct array { __array_traits<_Nm>::_Type _M_elems; }; struct _Optional_payload_base { union { int _M_value; }; }; struct _Optional_base { constexpr _Optional_base(...) : _M_payload() {} constexpr _Optional_base(_Optional_base &&) {} _Optional_payload_base _M_payload; }; struct optional : _Optional_base, _Enable_copy_move { using _Base = _Optional_base; constexpr optional() {} template <typename _Up> constexpr optional(_Up __t) : _Base(forward(__t)) {} } page { array<8> {} } ``` gives me: ``` ➜ scratch /usr/bin/g++-12 -std=gnu++20 testcase.ii testcase.ii:24:1: in ‘constexpr’ expansion of ‘page.optional::optional<array<8> >(array<8>{__array_traits<8>::_Type()})’ testcase.ii:24:1: in ‘constexpr’ expansion of ‘forward(_Tp&) [with _Tp = array<8>]()’ testcase.ii:24:1: in ‘constexpr’ expansion of ‘array<8>((* &((array<8>&&)__t)))’ testcase.ii:24:1: in ‘constexpr’ expansion of ‘optional(<anonymous>.array<8>::_M_elems[0])’ testcase.ii:24:1: internal compiler error: in cxx_eval_component_reference, at cp/constexpr.cc:4136 24 | } | ^ 0x7fb4eb429d8f __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 0x7fb4eb429e3f __libc_start_main_impl ../csu/libc-start.c:392 Please submit a full bug report, with preprocessed source (by using -freport-bug). Please include the complete backtrace with any bug report. See <file:///usr/share/doc/gcc-12/README.Bugs> for instructions. ``` with ``` g++-12 (Ubuntu 12.2.0-3ubuntu1~22.04) 12.2.0 Copyright (C) 2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ``` unfortunately cvise didn't reduce the test case to valid c++ code (afaict there's only a missing semicolon, though). with a trailing semicolon, gcc-11 accepts the code, but clang++-15 doesn't (not sure if it's related, but i thought it's worth mentioning: ``` testcase.reduced.cc:21:63: error: cannot pass object of non-trivial type 'array<8>' through variadic constructor; call will abort at runtime [-Wnon-pod-varargs] template <typename _Up> constexpr optional(_Up __t) : _Base(forward(__t)) {} ^ testcase.reduced.cc:22:3: note: in instantiation of function template specialization 'optional::optional<array<8>>' requested here } page { ^ 1 error generated. ```