<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63544>63544</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[C++20] [Modules] The lambda in the requires expression prevents us to merge concepts across modules
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:modules
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
ChuanqiXu9
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ChuanqiXu9
</td>
</tr>
</table>
<pre>
This comes from https://github.com/llvm/llvm-project/issues/63530. I file this to track the issue in the compiler side.
Reproducer:
```
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
//
// RUN: %clang_cc1 -std=c++23 %t/a.cppm -emit-module-interface -o %t/m-a.pcm
// RUN: %clang_cc1 -std=c++23 %t/b.cppm -emit-module-interface -o %t/m-b.pcm
// RUN: %clang_cc1 -std=c++23 %t/m.cppm -emit-module-interface -o %t/m.pcm \
// RUN: -fprebuilt-module-path=%t
// RUN: %clang_cc1 -std=c++23 %t/use.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
//--- foo.h
namespace std {
struct strong_ordering {
int n;
constexpr operator int() const { return n; }
static const strong_ordering equal, greater, less;
};
constexpr strong_ordering strong_ordering::equal = {0};
constexpr strong_ordering strong_ordering::greater = {1};
constexpr strong_ordering strong_ordering::less = {-1};
} // namespace std
namespace std {
template <typename _Tp>
class optional {
private:
using value_type = _Tp;
value_type __val_;
bool __engaged_;
public:
constexpr bool has_value() const noexcept
{
return this->__engaged_;
}
constexpr const value_type& operator*() const& noexcept
{
return __val_;
}
optional(_Tp v) : __val_(v) {
__engaged_ = true;
}
};
template <class _Tp>
concept __is_derived_from_optional = requires(const _Tp& __t) { []<class __Up>(const optional<__Up>&) {}(__t); };
template <class _Tp, class _Up>
requires(!__is_derived_from_optional<_Up>)
constexpr strong_ordering
operator<=>(const optional<_Tp>& __x, const _Up& __v) {
return __x.has_value() ? *__x <=> __v : strong_ordering::less;
}
} // namespace std
//--- a.cppm
module;
#include "foo.h"
export module m:a;
export namespace std {
using std::optional;
using std::operator<=>;
}
//--- b.cppm
module;
#include "foo.h"
export module m:b;
export namespace std {
using std::optional;
using std::operator<=>;
}
//--- m.cppm
export module m;
export import :a;
export import :b;
//--- use.cpp
// expected-no-diagnostics
import m;
int use() {
std::optional<int> a(43);
int t{3};
return a<=>t;
}
```
The root cause is that we treat the lambda expressions in `__is_derived_from_optional ` as different expressions in module `m:a` and `m:b`. This may be related to https://github.com/llvm/llvm-project/issues/57222
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMV0-P4rgS_zTmUgoKNglw4EDDIL3De4dRt_RukeNUwDtJnLEdlv72Kzt_oWG2Nb2HbbWApMq_-tUfl13cGHmqELckeiGU7s8Nr37K_zcbQimJDjPe2LPS2_H9LFXZ-_b1LA0IVaKBXKsSztbWhrAdoUdCjydpz006F6ok9FgUl_4rqLX6A4Ul9CiNadAQeoxZxMI5_AdyWSBYh2sVWM3FD7BnBK8IsvIPQpW1LFCDkRnOSXgg4a79_I61VlkjUDsWEwGJw-6_ffQE4fvb_wjbgS4h0DkQGtlH4vJHJjUE9VMFUxfSBp45oZH5oPdoDaGRKHh1SoRYQGBsRthBEPpC6AtlLQI98rmo6xICLKUNSpU1BQaysqhzLhAC1euVAZ_XovxtO-mn7aRfslN-1o6zAiTaP7IU5LXGtJHFAFFzeybs8Cw9n6LWGHTkfo0OQW7eK8uvgaqKdwguqGX-flNn3nIQBJArNT9PRRUv0dTOUWMzIKuX9rWxuhEWjNWqOiVKZ6hldRrlALKyUBHWPwtVGYvXWoOqUXOrtNMgdE3ophW6xaDRNrryC4GsDj2YsdxK0endG8WfDS8I3cNJI7eo3c8CjRmMO6D-98jjHubu2W1FtvPYQNjBsQu_ANRx66EWX4ByvvU4wQ0QWR2gq6KbvH0ioRbLuuAWgbC9fa_RqUHyWhP2rSNZcGNA1VaqyoWkX1hreeEWh84FANAYR_7CiwYT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