<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/102721>102721</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang][Modules] Import then include fails to merge inline lambdas
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
davidstone
</td>
</tr>
</table>
<pre>
Given the following valid translation units:
```c++
module;
inline auto x = []{};
export module a;
```
```c++
module;
import a;
inline auto x = []{};
export module b;
```
clang erroneously rejects with
```console
b.cpp:5:13: error: redeclaration of 'x' with a different type: '(lambda at /app/b.cpp:5:17)' vs '(lambda at /app/a.cpp:3:17)'
5 | inline auto x = []{};
| ^
a.cpp:3:13: note: previous definition is here
3 | inline auto x = []{};
| ^
1 error generated.
```
See it live: https://godbolt.org/z/WxW47zW4v
This is the reduced version of the following reproducer:
```c++
module;
#include <compare>
export module a;
```
```c++
module;
import a;
#include <compare>
export module b;
```
in which clang with libc++ erroneously rejects with
```console
In file included from /app/b.cpp:4:
In file included from /opt/compiler-explorer/clang-assertions-trunk-20240809/bin/../include/c++/v1/compare:156:
/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/../include/c++/v1/__compare/synth_three_way.h:28:45: error: redeclaration of '__synth_three_way' with a different type: 'const std::__1::(lambda at /opt/compiler-explorer/clang-assertions-trunk-20240809/bin/../include/c++/v1/__compare/synth_three_way.h:28:65)' vs 'const std::__1::(lambda at /opt/compiler-explorer/clang-assertions-trunk-20240809/bin/../include/c++/v1/__compare/synth_three_way.h:28:65)'
28 | _LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way = []<class _Tp, class _Up>(const _Tp& __t, const _Up& __u)
| ^
/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/../include/c++/v1/__compare/synth_three_way.h:28:45: note: previous definition is here
28 | _LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way = []<class _Tp, class _Up>(const _Tp& __t, const _Up& __u)
| ^
1 error generated.
```
See it live: https://godbolt.org/z/4dK717sr4
Looks like the library side of it was reintroduced by https://github.com/llvm/llvm-project/commit/d043e4c322489fa5b9f6363e3c83984219c2b602 @H-G-Hristov, @Zingam but I suspect that the clang side of it was never fully fixed. https://github.com/llvm/llvm-project/issues/57222 @ChuanqiXu9 shows a unit test for two modules that just include a header with an inline lambda, but this case of import module that included, followed by include appears to have slipped through.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUV12TmzoS_TXyS5ddIMCYBz_Y45BMbVKb2k0qW_tCCWiMElniSgLb-fW3JPCMZ3KT3Jn7lVCuGSyru0-fVp8GZgzfS8Q1SbYk2c1Yb1ul1zUbeG2skjgrVX1ev-QDSrAtQqOEUEcu9zAwwWuwmkkjmOVKQi-5NSTakGBHgsvfZTB-KkK37uNXD6ruBZJoe72VS8ElAuutghOQaAcjKJJuSbp7tBlPndIWRkfA7n-9xHsuiIP3y_48bOW3sVWCyT2g1kqi6o04g8aPWFkDR27b385CSaMEjqvlouo6Em0SEm3CiEQb70u7G401VoLpsTqqAULTE6Gp9wwMat40qFFasOcOnQWhKaErwQ5lzYBZIDRnXUdo_iBKSmjm3Azm6wZsMoiuDEbAAAAJkPQGfiep4C9nQJIX49ID7z5pqazPoNM4cNUbqLHhkvvMuYEWNd57i54X_vq6gxKOfMMeJWpmsV58o9j_RQRuQfDBg22t7XzD0JzQfK_qUgm7UHpPaP6Z0PzD6UOcfv4QD9c-3rXcuJRcN2qs-wprGFCbqcYPm1Rjp5Xbo5_fl4RGXFairxFIdFOpQ8c0kujFP9OOTwbznf7jEo4tr1oYG9G3huDlBO0PNOathIYLhAluDY1Why87Kr4rzFcNVGcJzV2uXKCe46kTSqN2aw7znBmD2p10M7e6l5_mNKBxsAoyF4ZLQvPFgtB88uvMJt5pPoSTZ8_iJkyW9-fkrw9cFJfQNDdnadvCthqxOLLzoiXRhq4cQcl3Ra0oHll_T-Rco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