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

            Bug ID: 122884
           Summary: regression: gcc crashed on lambda within require
                    clause or noexcept clause
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rungecc at gmail dot com
  Target Milestone: ---

Reproducer(https://godbolt.org/z/G8cfbzWrn):
```cxx
// gcc -std=c++26 -Wall -Wextra -Werror 
struct demux_t {
    template <class Fn, class... Slots>
    static constexpr auto operator()(Fn&& fn, Slots&&... slots) {
        return [fn{fn}, ... slots{slots}]<class Self, class... Args>(
                   this Self&&,
                   Args&&... args) 
                   noexcept(noexcept(fn(slots(args...)...))) // comment this
                   -> decltype(auto)
                   requires requires { fn(slots(args...)...); } // and this, no
longer crash
        { return fn(slots(args...)...); };
    }
} static constexpr demux{};

static_assert(demux([](auto x, auto y) { return x + y; },
                    [](auto...) { return 1; },
                    [](auto...) { return 2; })(1, 2) == 3);

```

gcc trunk crashed with:

```
<source>: In instantiation of 'static constexpr auto demux_t::operator()(Fn&&,
Slots&& ...) [with Fn = <lambda(auto:1, auto:2)>; Slots = {<lambda(auto:3
...)>, <lambda(auto:4 ...)>}]':
required from here
<source>:14:20:   
   14 | static_assert(demux([](auto x, auto y) { return x + y; },
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   15 |                     [](auto...) { return 1; },
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~
   16 |                     [](auto...) { return 2; })(1, 2) == 3);
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:7:40: internal compiler error: Segmentation fault
    7 |                    noexcept(noexcept(fn(slots(args...)...))) // comment
this
      |                                      ~~^~~~~~~~~~~~~~~~~~~
0x2914fd8 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x2909d9b internal_error(char const*, ...)
        ???:0
0xd8ba43 tsubst_pack_expansion(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xd83eaa tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xd763a0 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xdae03d instantiate_decl(tree_node*, bool, bool)
        ???:0
0xc241b3 maybe_instantiate_decl(tree_node*)
        ???:0
0xc25fb7 mark_used(tree_node*, int)
        ???:0
0xb4cfe3 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
        ???:0
0xdd3265 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0xd4c213 c_parse_file()
        ???:0
0xebbf99 c_common_parse_file()
        ???: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
```

Expected: do not crashing, as msvc, clang and gcc 15.2 does.

Reply via email to