<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58819>58819</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            externally visible lambda in a static data member of a class is given internal linkage and wrong mangled name
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          zygoloid
      </td>
    </tr>
</table>

<pre>
    Testcase:

```
struct A {
    static constexpr auto x = [] { static int n; return &n; };
};
int *f() {
    return A::x();
}
```

`A::x()` is required to return the same address in every translation unit. But Clang emits the lambda and its static local with internal linkage and with a vendor-specific `$_n` mangling:

```
@_ZN1A1xE = internal constant %class.anon undef, align 1, !dbg !0
@"_ZZNK1A3$_0clEvE1n" = internal global i32 0, align 4, !dbg !5
; ...
define internal noundef ptr @"_ZNK1A3$_0clEv"(ptr noundef nonnull align 1 dereferenceable(1) %0) #1 align 2 !dbg !7 {
```

See this [live on compiler explorer](https://godbolt.org/z/fr7br1hnE).

See also the [relevant ABI rule](http://itanium-cxx-abi.github.io/cxx-abi/abi.html#closure-types); the case we're in here is "the initializers of inline or templated variables".
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9VEGTqzYM_jVw0YQBAwkcOCQv-2Y6nXmX9rSXHYMFcWvs1DbZZH99ZSfZvOy8NgMxsmR9kj7JvRGX7k90fuAOk3Kb5Pskv_-v89sTReftMnjYQrLZXXeAfs5zLwcYjHYez0cLfPEGzpCUe0jqXVLvg_3dTGoPOil3YNEvVkPC1lFMNntabrA_fQf7hG3HhDUJa5-Rby62Iepye76aPHn5VRafm1_OrXOQjnz-s0iLAiiHm39_QHB8RuBCWHSOcgA8ob2At1w7RXkZDYuWPoPd4uGb4noCnKV38azicy84cC0gbN0KoczAFbxLfwg1QatJUlL_zSeMplHD4YRaGLtyRxzkSMdCGqx60yHcmXD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