Skip to content

[C++20] [Modules] Including <valarray> in GMF in front of other headers may violate ODR Checking #61643

Open
@ChuanqiXu9

Description

@ChuanqiXu9

We meet the problem twice now (#61642 and #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> affected the operator in the require clause. We can find the example in #61150. And the compilation completes after I remove the free standing operator in valarray. Here is the example: https://reviews.llvm.org/D146695

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:modulesC++20 modules and Clang Header Moduleslibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions