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

            Bug ID: 123683
           Summary: ICE (Segfault) in tsubst_default_argument when lambda
                    default arg is instantiated within another lambda
                    scope
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jirehguo at tju dot edu.cn
  Target Milestone: ---

Compiler Explorer: https://godbolt.org/z/KheT5coP9
The following c++ code crash gcc trunk.
Goes back to gcc 11.1.
Clang, gcc 10 and earlier verions accept the code.

Code:
```cpp
struct SimpleFunc {
    template <typename F> 
    SimpleFunc(F) {}
};

template <typename T> 
class MyClass {
public:
    static bool func(const int &x) {
        return x > 0;
    }

    unsigned int Find(SimpleFunc pFunc =
                        [](const int &x) {
                          return MyClass<int>::func(x);
                        }) const {
        return 1;
    }
};

int main() {
    MyClass<int> obj;
    auto stressLambda = [obj]() { 
        return obj.Find(); 
    };
}
```

Stack dump:
```
<source>: In lambda function:
<source>:24:24: internal compiler error: Segmentation fault
   24 |         return obj.Find();
      |                ~~~~~~~~^~
0x2950b58 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x294591b internal_error(char const*, ...)
        ???:0
0xd98464 tsubst_default_argument(tree_node*, int, tree_node*, tree_node*, int)
        ???:0
0xb3f902 convert_default_arg(tree_node*, tree_node*, tree_node*, int, int)
        ???:0
0xb407e3 build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
        ???:0
0xe034c9 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0xd64c43 c_parse_file()
        ???:0
0xeeed69 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
```

Reply via email to