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

            Bug ID: 127986
           Summary: [16 Regression] ICE in tsubst_expr, at cp/pt.cc:23146
                    on value-initialized aggregate whose array element has
                    a builtin NSDMI, inside a template
           Product: gcc
           Version: 16.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: karl at taniustech dot com
  Target Milestone: ---

GCC 16.2.0 crashes on valid code when a class whose member is an array of a
struct with a default member initializer calling a builtin (__builtin_inf(),
__builtin_nan(""), std::nan("")) is value-initialized with {} inside a function
template. The template does not need to be instantiated. GCC 13.2.0 and 15.2.0
accept the code.

Any one of these changes avoids the ICE: a constant initializer (double d =
0.0;), a non-array member (A a;), or B() instead of B{}. An ordinary function
call (double d = f();) in the NSDMI does not trigger it either.

Testcase (t.cc):

struct A { double d = __builtin_inf(); };
struct B { A a[1]; };
template <typename T> void h() { B{}; }
Command:

g++ -std=c++17 -fsyntax-only t.cc
Also fails with -std=c++20 and -std=gnu++20, and with or without optimization.

Output:

t.cc: In function 'void h()':
t.cc:3:36: internal compiler error: in tsubst_expr, at cp/pt.cc:23146
    3 | template <typename T> void h() { B{}; }
      |                                    ^
0x24367ff internal_error(char const*, ...)
        ../../gcc-16.2.0/gcc/diagnostic-global-context.cc:787
0x7f670f fancy_abort(char const*, int, char const*)
        ../../gcc-16.2.0/gcc/diagnostics/context.cc:1813
0x7aa307 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../gcc-16.2.0/gcc/cp/pt.cc:23146
0x861ef1 fold_non_dependent_expr_template
        ../../gcc-16.2.0/gcc/cp/constexpr.cc:11504
0x8622e8 fold_non_dependent_init(tree_node*, int, bool, tree_node*)
        ../../gcc-16.2.0/gcc/cp/constexpr.cc:11602
0xaa58a3 massage_init_elt
        ../../gcc-16.2.0/gcc/cp/typeck2.cc:1673
0xaa70b7 process_init_constructor_record
        ../../gcc-16.2.0/gcc/cp/typeck2.cc:1942
0xaa70b7 process_init_constructor
        ../../gcc-16.2.0/gcc/cp/typeck2.cc:2204
0xaa70b7 digest_init_r
        ../../gcc-16.2.0/gcc/cp/typeck2.cc:1494
0xa551fd finish_compound_literal(tree_node*, tree_node*, int, fcl_t)
        ../../gcc-16.2.0/gcc/cp/semantics.cc:3949
0x98fd82 cp_parser_functional_cast
        ../../gcc-16.2.0/gcc/cp/parser.cc:36667
g++ -v:

Target: x86_64-linux-gnu
Configured with: ../gcc-16.2.0/configure --host=x86_64-linux-gnu
--prefix=/opt/tanius/gcc-16.2.0 --with-gcc-major-version-only
--program-suffix=-16 --enable-languages=c,c++,fortran --enable-bootstrap
--with-tune=generic --enable-shared --enable-threads=posix
--enable-libstdcxx-backtrace --with-system-zlib --enable-linker-build-id
--with-default-libstdcxx-abi=new --disable-multilib --disable-libsanitizer
--disable-werror
gcc version 16.2.0
Possibly related: PR126811 (ICE in tsubst when a constexpr init contains an
NSDMI). That one is reported as failing since 14.1, whereas this testcase
compiles with 15.2.0, so it may be a separate regression in the same area.

Reply via email to