jiixyj wrote:

> Should we not use the DC of the variable (ie its parent) ?

Thanks for having a look! So in the example from the issue, i.e.:

```c++
    static inline int parse(int* i) {
        return [&] -> int { return i[0]; }();

        volatile bool b = false;
        if (b) {
            auto identifier = [&] -> int { return i[1]; }();
            return identifier;
        }
    }
```

...the `ManglingContextDecl` of the second lambda is the `VarDecl` of the local 
variable `identifier` (some debug output):

```txt
40 Var
VarDecl 0x56343b9495b8 <clang/test/Modules/pr178893.cppm:17:15, col:20> col:20 
in mod hidden identifier 'auto'
```

I want it to be `DC` instead, which is the `DeclContext` containing the lambda:

```
35 CXXMethod
CXXMethodDecl 0x56343b922cb0 <clang/test/Modules/pr178893.cppm:10:7, col:37> 
col:25 in mod hidden parse 'int (int *)' static inline
`-ParmVarDecl 0x56343b922b60 <col:31, col:36> col:36 in mod hidden used i 'int 
*'
```

So this is the `DeclContext` of the `parse` function, which is also the 
mangling context of the first lambda, IIUC. This is what you meant by the 
parent DC, right?

> Did you cross check with gcc?

I had a look in Compiler Explorer, and GCC generates code for both lambdas. But 
I haven't looked at GCC's code.

https://github.com/llvm/llvm-project/pull/179035
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to