https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120740

            Bug ID: 120740
           Summary: ICE: in build_data_member_initialization, at
                    cp/constexpr.cc:460
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: ice-checking, ice-on-invalid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rush102333 at gmail dot com
  Target Milestone: ---

$cat crash_10266.cpp
template <int... V>
struct A
{
  static constexpr int a[sizeof...(V)] = { V... };
};

template <int... V> constexpr int A<V...>::a[];

struct B
{
  const int* const b;

  template <unsigned int N>
  constexpr B(const int(&b)[N])
  : b(b)
  {}

  template <int... V>
  constexpr B(A<V...>)
  : B(A<V...>::a)
  {
__typeof__(sizeof(T) > 0) var;
if (var) {
}
 }
};

constexpr B b = A<10, 20, 30>();


$g++ -fsyntax-only crash_10266.cpp
<source>: In constructor 'constexpr B::B(A<V ...>)':
<source>:22:19: error: 'T' was not declared in this scope [-Wtemplate-body]
   22 | __typeof__(sizeof(T) > 0) var;
      |                   ^
<source>: At global scope:
<source>:28:17: error: 'constexpr B::B(A<V ...>) [with int ...V = {10, 20,
30}]' called in a constant expression
   28 | constexpr B b = A<10, 20, 30>();
      |                 ^~~~~~~~~~~~~~~
<source>:19:13: note: 'constexpr B::B(A<V ...>) [with int ...V = {10, 20, 30}]'
is not usable as a 'constexpr' function because:
   19 |   constexpr B(A<V...>)
      |             ^
<source>:19:13: internal compiler error: in build_data_member_initialization,
at cp/constexpr.cc:460
0x2839bc5 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
0x285b356 internal_error(char const*, ...)
        ???:0
0xae0316 fancy_abort(char const*, int, char const*)
        ???:0
0xb5cc3a explain_invalid_constexpr_fn(tree_node*)
        ???:0
0xdf038e store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
        ???:0
0xbdb55e cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
        ???:0
0xd07843 c_parse_file()
        ???:0
0xe6f329 c_common_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.


Please see https://godbolt.org/z/YEEM6Mc1r

Reply via email to