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

            Bug ID: 121597
           Summary: ICE: Segmentation fault, involving nested generic
                    lambda and argument deduction
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sneeddeens at mail dot ru
  Target Milestone: ---

gcc version 14.2.0 (GCC) 
Target: x86_64-pc-linux-gnu                                                     
Configured with: ../configure                                                   

Code compiled with: -Wall -Wextra -Wpedantic -std=c++20

But it seems any version of GCC can't compile example.
MSVC able to compile, Clang don't (see in Godbolt:
https://godbolt.org/z/qeeovMz3o)



Code:
template<int, class> struct Tmpl {};
template<typename T> struct Wrap {};

// needs to be a function template to trigger error
template<typename = void>
void foo()
{
  // making operator() to be template gives that ICE,
  // but non-template operator() also gives wrong
  // behavior from the compiler: 'Type' becomes void
  using Type = decltype([]<typename = void>{
    return Tmpl<0, char>{};
  }());

  // operator() needs to be a function template to trigger error
  []<typename = void>{
    using X = decltype([]<auto N, class T>(Tmpl<N, T>&&)
      {}.template operator()<0>(Type{}));
    // this 'Wrap' also needed to trigger error
    return Wrap<X>{};
  }();
};

template void foo<>();




Error output:
temp.cpp: In instantiation of ‘foo<>()::<lambda()> [with
<template-parameter-1-1> = void]’:
temp.cpp:1157:4:   required from ‘void foo() [with <template-parameter-1-1> =
void]’
 1152 |   []<typename = void>{
      |   ~~~~~~~~~~~~~~~~~~~~
 1153 |     using X = decltype([]<auto N, class T>(Tmpl<N, T>&&)
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1154 |       {}.template operator()<0>(Type{}));
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1155 |     // this 'Wrap' also needed to trigger error
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1156 |     return Wrap<X>{};
      |     ~~~~~~~~~~~~~~~~~
 1157 |   }();
      |   ~^~
temp.cpp:1160:21:   required from here
 1160 | template void foo<>();
      |                     ^
temp.cpp:1147:25: internal compiler error: Segmentation fault
 1147 |   using Type = decltype([]<typename = void>{
      |                         ^~~~~~~~~~~~~~~~~~~~
 1148 |     return Tmpl<0, char>{};
      |     ~~~~~~~~~~~~~~~~~~~~~~~
 1149 |   }());
      |   ~                      
0xf1d99f crash_signal
  ../../gcc/toplev.cc:319
0x903554 template_parms_to_args(tree_node*)
  ../../gcc/cp/pt.cc:4950
0x92da66 tsubst_template_decl
  ../../gcc/cp/pt.cc:15037
0x92f724 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
  ../../gcc/cp/pt.cc:19832
0x919e1d tsubst_expr(tree_node*, tree_node*, int, tree_node*)
 ../../gcc/cp/pt.cc:21806
0x9176fb tsubst_expr(tree_node*, tree_node*, int, tree_node*)
 ../../gcc/cp/pt.cc:20847
0x91f06a tsubst(tree_node*, tree_node*, int, tree_node*)
  ../../gcc/cp/pt.cc:16970
0x917bf5 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
 ../../gcc/cp/pt.cc:21325
0x91e264 tsubst_call_args
 ../../gcc/cp/pt.cc:19994
0x917747 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
 ../../gcc/cp/pt.cc:20855
0x91f06a tsubst(tree_node*, tree_node*, int, tree_node*)
  ../../gcc/cp/pt.cc:16970
0x920788 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
  ../../gcc/cp/pt.cc:13964
0x92bcc9 tsubst_aggr_type_1
 ../../gcc/cp/pt.cc:14239
0x92bcc9 tsubst_aggr_type_1
 ../../gcc/cp/pt.cc:14220
0x917bf5 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
 ../../gcc/cp/pt.cc:21325
0x92651f tsubst_stmt
  ../../gcc/cp/pt.cc:19529
0x927a9f tsubst_stmt
  ../../gcc/cp/pt.cc:18457
0x927a9f tsubst_stmt
  ../../gcc/cp/pt.cc:18481
0x927ad8 tsubst_stmt
  ../../gcc/cp/pt.cc:18457
0x927ad8 tsubst_stmt
  ../../gcc/cp/pt.cc:18471
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.




Here's bug report for Clang with similar problem, but without ICE, if
interested:
https://github.com/llvm/llvm-project/issues/154065

Reply via email to