<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61643>61643</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[C++20] [Modules] Including <valarray> in GMF in front of other headers may violate ODR Checking
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++,
clang:modules
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ChuanqiXu9
</td>
</tr>
</table>
<pre>
We meet the problem twice now (https://github.com/llvm/llvm-project/issues/61642 and https://github.com/llvm/llvm-project/issues/61150) so it may make sense to create a summary issue for this to avoid wider confusion.
Here is the reproducer:
```
// a.cppm
module;
#include <ranges>
export module a;
// b.cppm
module;
#include <valarray>
#include <ranges>
export module b;
import a;
```
Compile it with:
```
clang++ -std=c++2b $(STL_PATH) a.cppm --precompile -o a.pcm
clang++ -std=c++2b $(STL_PATH) b.cppm -fmodule-file=a=a.pcm --precompile -o b.pcm
```
((STL_PATH) refer to libcxx HEAD in my reproducer). And it gives error diagnostics:
```
In module 'a' imported from b.cppm:5:
/home/chuanqi.xcq/workspace.xuchuanqi/llvm-project-for-work/build/61642/../../build_libcxx/include/c++/v1/variant:1743:16: error: 'std::__throw_if_valueless' has different definitions in different modules; definition in module 'a.<global>' first difference is function body
constexpr void __throw_if_valueless(_Vs&&... __vs) {
~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../build_libcxx/include/c++/v1/variant:1743:16: note: but in '' found a different body
constexpr void __throw_if_valueless(_Vs&&... __vs) {
~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In module 'a' imported from b.cppm:5:
/home/chuanqi.xcq/workspace.xuchuanqi/llvm-project-for-work/build/61642/../../build_libcxx/include/c++/v1/tuple:1562:1: error: 'std::__tuple_compare_three_way' has different definitions in different modules; definition in module 'a.<global>' first difference is function body
__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../build_libcxx/include/c++/v1/tuple:1562:1: note: but in '' found a different body
__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In module 'a' imported from b.cppm:5:
/home/chuanqi.xcq/workspace.xuchuanqi/llvm-project-for-work/build/61642/../../build_libcxx/include/c++/v1/__ranges/zip_view.h:494:40: error: 'std::__1::ranges::views::__zip::__fn::operator()' from module 'a.<global>' is not present in definition of 'std::__1::ranges::views::__zip::__fn' provided earlier
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Ranges&&... __rs) const
^
../../build_libcxx/include/c++/v1/__ranges/zip_view.h:491:40: note: declaration of 'operator()' does not match
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()() const noexcept { return empty_view<tuple<>>{}; }
^
../../build_libcxx/include/c++/v1/__ranges/zip_view.h:494:40: note: declaration of 'operator()' does not match
_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Ranges&&... __rs) const
```
According to my analysis, this is caused by the free standing operators in <valarray> affects the operator in the require clause. We can find the example in https://github.com/llvm/llvm-project/issues/61150. And the compilation completes after I remove the free standing operator in valarray. Here is the example:
Although I add the libcxx tag, I am not sure that this is libcxx bug. I just add it to CC the libcxx folks. Since I met this in libstdc++ too. Maybe this is a defect in the spec.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWFtv6zYS_jX0y8CCTVm-PPjBl3iPgR704PTsdt8EihpZbCRSISlf-tDfvhhdbCc9G6TJLrbF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