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

            Bug ID: 122681
           Summary: ICE when invoking explicit destructor on a
                    non-captured constexpr variable within a lambda
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ing.russomauro at gmail dot com
  Target Milestone: ---

This code fails on godbolt (https://godbolt.org/z/re6do7W6z)
with gcc-trunk, not with gcc 15.2, don't know about 16.0
Anyway, it seems a recent regression.

struct S{
    constexpr S(){}
    void f(){}
};

int main(){
    constexpr S x;

    auto lambda = [](){x.~S();}; // ICE here
    //auto lambda = [](){x.f();}; //no error
}

If 'constexpr' is removed for the variable 's', then no ICE.
If x.f() is invoked instead of x.~S(), then no ICE.


The compiler output reads:

<source>:9:24: error: 'x' is not captured
    9 |     auto lambda = [](){x.~S();};
      |                        ^
<source>:9:20: note: the lambda has no capture-default
    9 |     auto lambda = [](){x.~S();};
      |                    ^
<source>:7:17: note: 'constexpr const S x' declared here
    7 |     constexpr S x;
      |                 ^
<source>:9:28: internal compiler error: Segmentation fault
    9 |     auto lambda = [](){x.~S();};
      |                        ~~~~^~
0x290d368 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x290215b internal_error(char const*, ...)
        ???:0
0xb2d7eb build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
        ???:0
0xdcc4e9 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0xd45a53 c_parse_file()
        ???:0
0xeb4989 c_common_parse_file()
        ???:0

Reply via email to