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

            Bug ID: 118240
           Summary: ## ICE Segmentation fault with default non-type
                    template parameter(on PR103943)
           Product: gcc
           Version: 15.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: ---

Extended from PR103943, the crash happens when a non-type template parameter
with a default value is appended to the existing template classes.

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

$g++ -freport-bug m103943.cpp

<source>:4:22: error: parameter pack 'AA' must be at the end of the template
parameter list
    4 | template<typename R, typename...AA, typename NOS=int> struct F0 { //OK
      |                      ^~~~~~~~
<source>:7:22: error: parameter pack 'AA' must be at the end of the template
parameter list
    7 | template<typename R, typename...AA, int NON=0> struct F1 { //OK
      |                      ^~~~~~~~
<source>:11:22: error: parameter pack 'AA' must be at the end of the template
parameter list
   11 | template<typename R, typename...AA, int NON=0> struct F2 { //OK
      |                      ^~~~~~~~
<source>:16:22: error: parameter pack 'AA' must be at the end of the template
parameter list
   16 | template<typename R, typename...AA, typename NOS=int> struct F3 {
      |                      ^~~~~~~~
<source>:23:22: error: parameter pack 'AA' must be at the end of the template
parameter list
   23 | template<typename R, typename...AA, int NON=0> struct F4 {
      |                      ^~~~~~~~
<source>:30:22: error: parameter pack 'AA' must be at the end of the template
parameter list
   30 | template<typename R, typename...AA, int NON=0> struct F5 { //OK
      |                      ^~~~~~~~
<source>:36:22: error: parameter pack 'AA' must be at the end of the template
parameter list
   36 | template<typename R, typename...AA, int NON=0> struct F6 {
      |                      ^~~~~~~~
<source>:44:74: note: so any instantiation with a non-empty parameter pack
would be ill-formed
   44 | template<typename R, typename...AA> F0(R(*fun_ptr)(AA...)) -> F0<R,
AA...>;
      |                                                                        
 ^
<source>:44:63: error: trailing return type '<type error>' of deduction guide
is not a specialization of 'F0<R, <declaration error>, NOS>'
   44 | template<typename R, typename...AA> F0(R(*fun_ptr)(AA...)) -> F0<R,
AA...>;
      |                                                              
^~~~~~~~~~~~
<source>:45:74: note: so any instantiation with a non-empty parameter pack
would be ill-formed
   45 | template<typename R, typename...AA> F1(R(*fun_ptr)(AA...)) -> F1<R,
AA...>;
      |                                                                        
 ^
<source>:45:63: error: trailing return type '<type error>' of deduction guide
is not a specialization of 'F1<R, <declaration error>, NON>'
   45 | template<typename R, typename...AA> F1(R(*fun_ptr)(AA...)) -> F1<R,
AA...>;
      |                                                              
^~~~~~~~~~~~
<source>:46:74: note: so any instantiation with a non-empty parameter pack
would be ill-formed
   46 | template<typename R, typename...AA> F2(R(*fun_ptr)(AA...)) -> F2<R,
AA...>;
      |                                                                        
 ^
<source>:46:63: error: trailing return type '<type error>' of deduction guide
is not a specialization of 'F2<R, <declaration error>, NON>'
   46 | template<typename R, typename...AA> F2(R(*fun_ptr)(AA...)) -> F2<R,
AA...>;
      |                                                              
^~~~~~~~~~~~
<source>:47:74: note: so any instantiation with a non-empty parameter pack
would be ill-formed
   47 | template<typename R, typename...AA> F3(R(*fun_ptr)(AA...)) -> F3<R,
AA...>;
      |                                                                        
 ^
<source>:47:63: error: trailing return type '<type error>' of deduction guide
is not a specialization of 'F3<R, <declaration error>, NOS>'
   47 | template<typename R, typename...AA> F3(R(*fun_ptr)(AA...)) -> F3<R,
AA...>;
      |                                                              
^~~~~~~~~~~~
<source>:48:74: note: so any instantiation with a non-empty parameter pack
would be ill-formed
   48 | template<typename R, typename...AA> F4(R(*fun_ptr)(AA...)) -> F4<R,
AA...>;
      |                                                                        
 ^
<source>:48:63: error: trailing return type '<type error>' of deduction guide
is not a specialization of 'F4<R, <declaration error>, NON>'
   48 | template<typename R, typename...AA> F4(R(*fun_ptr)(AA...)) -> F4<R,
AA...>;
      |                                                              
^~~~~~~~~~~~
<source>:49:74: note: so any instantiation with a non-empty parameter pack
would be ill-formed
   49 | template<typename R, typename...AA> F5(R(*fun_ptr)(AA...)) -> F5<R,
AA...>;
      |                                                                        
 ^
<source>:49:63: error: trailing return type '<type error>' of deduction guide
is not a specialization of 'F5<R, <declaration error>, NON>'
   49 | template<typename R, typename...AA> F5(R(*fun_ptr)(AA...)) -> F5<R,
AA...>;
      |                                                              
^~~~~~~~~~~~
<source>:50:74: note: so any instantiation with a non-empty parameter pack
would be ill-formed
   50 | template<typename R, typename...AA> F6(R(*fun_ptr)(AA...)) -> F6<R,
AA...>;
      |                                                                        
 ^
<source>:50:63: error: trailing return type '<type error>' of deduction guide
is not a specialization of 'F6<R, <declaration error>, NON>'
   50 | template<typename R, typename...AA> F6(R(*fun_ptr)(AA...)) -> F6<R,
AA...>;
      |                                                              
^~~~~~~~~~~~
<source>: In function 'void test()':
<source>:57:22: error: class template argument deduction failed:
   57 |     auto f0 = F0{&fun}; //OK
      |                      ^
<source>:57:22: error: no matching function for call to 'F0(int (*)(int))'
<source>:57:22: note: there are 2 candidates
<source>:4:62: note: candidate 1: 'template<class R, <declaration error>, class
NOS> F0() -> F0<R, <declaration error>, NOS>'
    4 | template<typename R, typename...AA, typename NOS=int> struct F0 { //OK
      |                                                              ^~
<source>:4:62: note: candidate expects 0 arguments, 1 provided
<source>:4:62: note: candidate 2: 'template<class R, <declaration error>, class
NOS> F0(F0<R, <declaration error>, NOS>) -> F0<R, <declaration error>, NOS>'
<source>:4:62: note: template argument deduction/substitution failed:
<source>:57:22: note:   mismatched types 'F0<R, <declaration error>, NOS>' and
'int (*)(int)'
   57 |     auto f0 = F0{&fun}; //OK
      |                      ^
<source>:13:32: error: using invalid field 'F2<R, <declaration error>,
NON>::fun_ptr'
   13 |     using fun_ptr_t = decltype(fun_ptr);
      |                                ^~~~~~~
<source>:13:32: error: using invalid field 'F2<R, <declaration error>,
NON>::fun_ptr'
<source>:19:32: error: using invalid field 'F3<R, <declaration error>,
NOS>::fun_ptr'
   19 |     using fun_ptr_t = decltype(F3::fun_ptr); //ICE: Segmentation fault
      |                                ^~
<source>:19:32: error: using invalid field 'F3<R, <declaration error>,
NOS>::fun_ptr'
<source>:61:22: error: class template argument deduction failed:
   61 |     auto f4 = F4{&fun}; //OK
      |                      ^
<source>:61:22: error: no matching function for call to 'F4(int (*)(int))'
<source>:61:22: note: there are 2 candidates
<source>:23:55: note: candidate 1: 'template<class R, <declaration error>, int
NON> F4() -> F4<R, <declaration error>, NON>'
   23 | template<typename R, typename...AA, int NON=0> struct F4 {
      |                                                       ^~
<source>:23:55: note: candidate expects 0 arguments, 1 provided
<source>:23:55: note: candidate 2: 'template<class R, <declaration error>, int
NON> F4(F4<R, <declaration error>, NON>) -> F4<R, <declaration error>, NON>'
<source>:23:55: note: template argument deduction/substitution failed:
<source>:61:22: note:   mismatched types 'F4<R, <declaration error>, NON>' and
'int (*)(int)'
   61 |     auto f4 = F4{&fun}; //OK
      |                      ^
<source>:32:32: internal compiler error: Segmentation fault
   32 |     using fun_ptr_t = decltype(&fun_not_implemented);
      |                                ^~~~~~~~~~~~~~~~~~~~
0x2937c55 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
0x294ea56 internal_error(char const*, ...)
        ???:0
0xd25b57 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xd04606 do_auto_deduction(tree_node*, tree_node*, tree_node*, int,
auto_deduction_context, tree_node*, int, tree_node*)
        ???:0
0xd63081 finish_compound_literal(tree_node*, tree_node*, int, fcl_t)
        ???:0
0xce54ba c_parse_file()
        ???:0
0xe44d69 c_common_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Reply via email to