Bug 115588 - ICE: in tsubst_stmt, at cp/pt.cc:18527
Summary: ICE: in tsubst_stmt, at cp/pt.cc:18527
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 15.0
: P4 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, error-recovery, ice-on-invalid-code, ice-on-invalid-fuzzy
Depends on:
Blocks: C++VLA
  Show dependency treegraph
 
Reported: 2024-06-22 08:39 UTC by Anonymous
Modified: 2026-01-15 04:21 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anonymous 2024-06-22 08:39:47 UTC
*******************************************************************************
The compiler produces an internal error during the tsubst_lambda_expr when compiling the provided code with the specified options. 
The issue can also be reproduced on Compiler Explorer.

*******************************************************************************
OS and Platform:
# uname -a
Linux ubuntu 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
*******************************************************************************
# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/root/gdbtest/gcc/gcc-15/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /root/gdbtest/gcc/obj/../gcc/configure --prefix=/root/gdbtest/gcc/gcc-15 --enable-languages=c,c++,fortran,go --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20240509 (experimental) (GCC) 
*******************************************************************************
Program:
# cat t.c

template <int N>
int f (int n)
{
  int x[1][n];

  return [x[0]] /* () { return 0; } */; 
}

int i = f<1>(1);



*******************************************************************************
Command Lines:
# g++ t.c -flto -fwhole-program -g -gdwarf-4 -ggdb3 -grecord-gcc-switches -fanalyzer -fdump-analyzer -Wno-analyzer-nul
l-dereference -Wno-analyzer-use-after-free -c -o t.o
t.c: In function ‘int f(int)’:
t.c:6:12: error: expected ‘,’ before ‘[’ token
    6 |   return [x[0]] /* () { return 0; } */;
      |            ^
      |            ,
t.c:6:12: error: expected identifier before ‘[’ token
t.c: In lambda function:
t.c:6:39: error: expected ‘{’ before ‘;’ token
    6 |   return [x[0]] /* () { return 0; } */;
      |                                       ^
t.c: In instantiation of ‘int f(int) [with int N = 1]’:
t.c:9:13:   required from here
    9 | int i = f<1>(1);
      |         ~~~~^~~
t.c:6:10: sorry, unimplemented: capture of variably-modified type ‘int [1][n]’ that is not an N3639 array of runtime bound
    6 |   return [x[0]] /* () { return 0; } */;
      |          ^~~~~~
t.c:6:10: note: because the array element type ‘int [n]’ has variable size
t.c:6:15: internal compiler error: in tsubst_stmt, at cp/pt.cc:18514
    6 |   return [x[0]] /* () { return 0; } */;
      |               ^
0x8308a0 tsubst_stmt
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/pt.cc:18514
0xce1718 tsubst_stmt
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/pt.cc:18410
0xce1718 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/pt.cc:19850
0xcbe1a0 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/pt.cc:21757
0xcc4837 tsubst_stmt
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/pt.cc:19482
0xcc6446 tsubst_stmt
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/pt.cc:18434
0xcc6106 tsubst_stmt
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/pt.cc:18410
0xcc6106 tsubst_stmt
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/pt.cc:18424
0xcc6bee tsubst_stmt
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/pt.cc:18797
0xce0b52 tsubst_stmt
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/pt.cc:18410
0xce0b52 instantiate_body
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/pt.cc:27107
0xcc4425 instantiate_decl(tree_node*, bool, bool)
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/pt.cc:27392
0xcf0c4b instantiate_pending_templates(int)
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/pt.cc:27468
0xb8cc67 c_parse_final_cleanups()
        /root/gdbtest/gcc/obj/../gcc/gcc/cp/decl2.cc:5195
0xddf3a0 c_common_parse_file()
        /root/gdbtest/gcc/obj/../gcc/gcc/c-family/c-opts.cc:1329
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.


*******************************************************************************

Also ICE on trunk, compiler explorer:https://godbolt.org/z/4j14rxbfr

*******************************************************************************