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

            Bug ID: 120618
           Summary: ICE: tree check: expected template_type_parm, have
                    boolean_type in write_requirement, at
                    cp/mangle.cc:3134
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamanonymous.cs at gmail dot com
  Target Milestone: ---
            Target: x86_64

*******************************************************************************
The compiler produces an internal error during write_requirement 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-250610/libexec/gcc/x86_64-pc-linux-gnu/16.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-master/configure --prefix=/root/gdbtest/gcc/gcc-250610
--enable-languages=c,c++ --disable-multilib --disable-bootstrap :
(reconfigured) ../gcc-master/configure --prefix=/root/gdbtest/gcc/gcc-250610
--enable-languages=c,c++ --disable-multilib --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.0.0 20250610 (experimental) (GCC)
*******************************************************************************
Program:
#cat code.cpp

 #include<iostream>
 #include<cstring>
 #include<vector>

 class A{};
 class B{};

 bool foo(A a) {
   return true;
 }


 template<typename T>
 requires !requires(T a) { { foo(a) } -> bool }
 bool foo(T a) {
   return true;
 }


 int main() {
   A a;
   B b;
   foo(a);
   foo(b);
 }


*******************************************************************************
Command Lines:
gcc code.cpp -std=c++20 -Werror -Wunused-result  -c -o code_0.o


<source>:14:42: error: return-type-requirement is not a type-constraint
   14 |  requires !requires(T a) { { foo(a) } -> bool }
      |                                          ^~~~
<source>:14:46: error: expected ';' before '}' token
   14 |  requires !requires(T a) { { foo(a) } -> bool }
      |                                              ^~
      |                                              ;
<source>:14:11: error: expression must be enclosed in parentheses
   14 |  requires !requires(T a) { { foo(a) } -> bool }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |           (                                    )
<source>: In substitution of 'template<class T>  requires !requires(T a)
{{foo(A)(a)} -> bool;} bool foo(T) [with T = B]':
<source>:14:33:   required by substitution of 'template<class T>  requires
!requires(T a) {{foo(A)(a)} -> bool;} bool foo(T) [with T = B]'
   14 |  requires !requires(T a) { { foo(a) } -> bool }
      |                              ~~~^~~
<source>:24:7:   required from here
   24 |    foo(b);
      |    ~~~^~~
<source>:15:7:   required by the constraints of 'template<class T>  requires
!requires(T a) {{foo(A)(a)} -> bool;} bool foo(T)'
<source>:14:11: error: satisfaction of atomic constraint '!requires(T a)
{{foo(A)(a)} -> bool;} [with T = T]' depends on itself
   14 |  requires !requires(T a) { { foo(a) } -> bool }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:15:7: internal compiler error: tree check: expected
template_type_parm, have boolean_type in write_requirement, at
cp/mangle.cc:3134
   15 |  bool foo(T a) {
      |       ^~~
0x282f995 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
0x284de16 internal_error(char const*, ...)
        ???:0
0x9e4d68 tree_check_failed(tree_node const*, char const*, int, char const*,
...)
        ???:0
0xc2d3f9 mangle_decl(tree_node*)
        ???:0
0x17ee7b5 decl_assembler_name(tree_node*)
        ???:0
0xf43ea1 symbol_table::finalize_compilation_unit()
        ???: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.
Compiler returned: 1
*******************************************************************************

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

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

Reply via email to