<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/98963>98963</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
lambda in class body should have the same type among different TUs
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
namniav
</td>
</tr>
</table>
<pre>
[basic.def.odr#15.6](https://eel.is/c++draft/basic.def.odr#15.6)
> In each such definition, except within the default arguments and default template arguments of `D`, corresponding *lambda-expression*s shall have the same closure type
When the lambda expression is used with `decltype` in side class body(but not inside a function), Clang with libc++ generates different closure types in different TUs.
Clang with libstdc++ seems not have this problem. GCC also has this problem for both `F1` and `F2`.
Demo: https://godbolt.org/z/M4xjWesYn
* common.hpp
```c++
#include <typeinfo>
#include <array>
struct A {
using F1 = decltype([]{}); // Clang with libc++ generates different closure types for different TUs
inline static auto f2 = []{};
using F2 = decltype(f2); // Clang Ok, GCC No
};
[[gnu::always_inline]]
inline auto func() {
using F3 = decltype([]{}); // OK
auto f4 = []{};
using F4 = decltype(f4); // OK
return std::array{ &typeid(F3), &typeid(F4) };
}
auto FOOBAR() {
auto t = func();
return std::array{
&typeid(A::F1),
&typeid(A::F2),
t[0],
t[1]
};
}
```
* foo.cpp
```c++
#define FOOBAR foo
#include "common.hpp"
```
* bar.cpp
```c++
#define FOOBAR bar
#include "common.hpp"
```
* main.cpp
```c++
#include <cstdio>
#include <typeinfo>
#include <array>
std::array<const std::type_info*, 4> foo();
std::array<const std::type_info*, 4> bar();
int main() {
auto f = foo();
auto b = bar();
for (int i = 0; i < 4; ++i) {
std::printf("F%d same type ? %d\n", i+1, *f[i] == *b[i]);
//std::printf("name=%s hash_code=%-20llu addr=%p\n", f[i]->name(), (unsigned long long)f[i]->hash_code(), f[i]);
//std::printf("name=%s hash_code=%-20llu addr=%p\n", b[i]->name(), (unsigned long long)b[i]->hash_code(), b[i]);
}
}
```
**Outputs** :
* Clang, libc++
> ```
> F1 same type ? 0
> F2 same type ? 1
> F3 same type ? 1
> F4 same type ? 1
> ```
* Clang, libstdc++
> ```
> F1 same type ? 1
> F2 same type ? 1
> F3 same type ? 1
> F4 same type ? 1
> ```
* GCC, libstdc++
> ```
> F1 same type ? 0
> F2 same type ? 0
> F3 same type ? 1
> F4 same type ? 1
> ```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV1Fv2zYQ_jX0yyGGREm2_OAH2Y6KYdgCDBuKPRWUSFnsKFIQqbTZrx-OUiwpsdu0HbaiUGse-d13H--OJLNWnrUQe5IcSHJasd7Vpttr1mjJHleF4U9oKpiV5ZqLam14R2gUJusNSU6EprVzrSVRRmhOaC6EWktLaF4SeiD0wDtWOULzq-vpjgQnEmQkuoefNAhW1mD7sgYuKqmlk0YTegTxuRStg0_S1VKDqwXaWa8csO7cN0I7C0zzy6gTTauYEzOzqYBsghPZBAhYmq4TtjWaS30GQjPFmoKzO_G57YS13m1mwdZMKajZo_BOLWsElMrYvhPgnloxkvff97UYqA1QMEGBtNBbwT1_ZMFFqfzyTQBSg5UcYZm1gGITmha9A20cSO1tDKpel4MYO6R_VEyfBzgli1FoOAstOuaEBS6rSnRCuwVbi84m0-9_2PVAfQlnHX9GtEI01jMZNZAW2s4USjRreHc8AlPWQM3swgSV6aAwQ6x5iFHi5uAPSjbBeq7aSTSGRBksc-hseGGUW5vuTGj-N6H5L_Hnj--F_VPPFxOaQWmaxuh13bbj2CYY_o4xPM-MpC5VzwWQ6IhiSF0ZEt1fM7OuY0-TzX-t6_rSQQZkO0ICAPQW0ycPgUQnuOwqTYdKwqnbE25ZdACAIbQbe_eGzUNVF7s38ZBaSS3AOuZkCax3BirqSS2YRK-p05fUK_pMeMH34S_MO9zyX82oywxw_KKvw1n3uI9RxtQn9mQ_DNyQRHIa5o1sB5q9LlEwuruqbPQGZUeeDz9Pqwfo-E0KxK8UiG8Dd8L1nQbr-BijT5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