https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101717
--- Comment #5 from Steven Sun <StevenSun2021 at hotmail dot com> ---
(In reply to Andrew Pinski from comment #4)
Thanks!
(In reply to myself from comment #3)
> The program seems never think of a situation "a lambda inside a lambda
> inside a NSDMI`. We need to amend the logic here.
edit to:
The program seems never think of a situation "member function call inside a
generic lambda inside a lambda inside a NSDMI`. We need to amend the logic
here.
-------------------------------------
The direct cause of failure is in g:91e534b0d
```
if (!containing_function && !COMPLETE_TYPE_P (closure))
/* If we're parsing a lambda in a non-local class,
we can find the fake 'this' in scope_chain. */
init = scope_chain->x_current_class_ptr;
```
This part of logic is to find the potential `this` since there is a (static)
member function call `f`. Refer to the following comments:
/* For the overload resolution we need to find the actual `this`
that would be captured if the call turns out to be to a
non-static member function. Do not actually capture it at this
point. */
// in function `build_new_method_call_1` in `gcc/cp/call.c`
-------------------------------------
As for example in comment 1:
`scope_chain->x_current_class_ptr` is correctly set when parsing
```
[=](auto) { f(); }
```
But it was soon incorrectly set when instantiating the same lambda, i.e.
parsing
```
[=](auto) { f(); }()
```
This failure only affectes the potential `this` pointer inside the
```
[=](auto) { f(); }
```
But since here needs no `this` pointer, deleting that problematical
`gcc_checking_assert` is actually a potential fix for this problem.