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

            Bug ID: 124203
           Summary: ICE when using non-captured variable in lambda in
                    concept `requires` clause
           Product: gcc
           Version: 15.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 4ernov at gmail dot com
  Target Milestone: ---

Created attachment 63758
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63758&action=edit
Auto-prepared report.

I've caught ICE when compiling these code (simplified example):

#include <tuple>

using namespace std;

namespace
{
        template<typename T> void woo(const T v) {}

        template<class T, class U> concept check = requires (T v, U u)
        {
                std::apply
                (
                        [](auto... args) // adding `v` to capture fixes
                        {
                                woo(v);
                        },
                        u
                );
        };
}

int main(int, char**)
{
        static_assert(check<int, std::tuple<double, float>>, "check failed");

        return 0;
}

The output is:

./main.cpp: In instantiation of '{anonymous}::<lambda(auto:3 ...)> [with auto:3
= {double, float}]':
/usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/type_traits:3333:30:  
required from 'struct std::is_nothrow_invocable<{anonymous}::<lambda(auto:3
...)>, double&, float&>'
 3333 |     : public __bool_constant<__is_nothrow_invocable(_Fn, _ArgTypes...)>
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/tuple:2904:31:   required
from 'constexpr const bool std::__unpack_std_tuple<template<class _Fn, class
... _ArgTypes> struct std::is_nothrow_invocable, {anonymous}::<lambda(auto:3
...)>, std::tuple<double, float>&>'
 2904 |       = _Trait<_Tp, _Up&...>::value;
      |                               ^~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/tuple:2931:14:   required
from 'constexpr decltype(auto) std::apply(_Fn&&, _Tuple&&) [with _Fn =
{anonymous}::<lambda(auto:3 ...)>; _Tuple = tuple<double, float>&]'
 2931 |     noexcept(__unpack_std_tuple<is_nothrow_invocable, _Fn, _Tuple>)
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./main.cpp:12:3:   required from here
   11 |                 std::apply
      |                 ~~~~~~~~~~
   12 |                 (
      |                 ^
   13 |                         [](auto... args)
      |                         ~~~~~~~~~~~~~~~~
   14 |                         {
      |                         ~
   15 |                                 woo(v);
      |                                 ~~~~~~~
   16 |                         },
      |                         ~~
   17 |                         u
      |                         ~
   18 |                 );
      |                 ~
./main.cpp:15:37: internal compiler error: in tsubst_expr, at cp/pt.cc:22039
   15 |                                 woo(v);
      |                                     ^
0x55b223fa4ccc diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
0x55b223f71a08 internal_error(char const*, ...)
        ???:0
0x55b223f71aff fancy_abort(char const*, int, char const*)
        ???:0
0x55b22433b2b1 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x55b22433b696 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x55b22443f0a0 instantiate_decl(tree_node*, bool, bool)
        ???:0
0x55b22443debb maybe_instantiate_decl(tree_node*)
        ???:0
0x55b22418a2df mark_used(tree_node*, int)
        ???:0
0x55b2248007d5 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**,
int)
        ???:0
0x55b2241b65aa finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**,
bool, bool, int)
        ???:0
0x55b22352f4ca build_invoke(tree_node*, tree_node const*, int)
        ???:0
0x55b2243e31f1 finish_trait_expr(unsigned long, cp_trait_kind, tree_node*,
tree_node*)
        ???:0
0x55b22433c37f tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x55b224373441 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x55b224296c6b tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x55b2242971f3 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x55b2243c5e3b instantiate_class_template(tree_node*)
        ???:0
0x55b223feaabd complete_type(tree_node*)
        ???:0
0x55b2240fa82b lookup_member(tree_node*, tree_node*, int, bool, int,
access_failure_info*)
        ???:0
0x55b2240c73eb lookup_qualified_name(tree_node*, tree_node*, LOOK_want, bool)
        ???:0
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.

After fixing the error in the code (adding `v` to lambda capture) it compiles
just fine.

Have tried my best to search for prior reports on this, sorry if it's still a
duplicate.

Reply via email to