Skip to content

[C++20] [Modules] False positive ODR Checking performs for template packs when generating BMI #61150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ChuanqiXu9 opened this issue Mar 3, 2023 · 2 comments
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules invalid Resolved as invalid, i.e. not a bug

Comments

@ChuanqiXu9
Copy link
Member

ChuanqiXu9 commented Mar 3, 2023

Reproducer:

//--- foo.h
namespace std
{
    template<class _Dom1>
    void operator &&(_Dom1 __v, _Dom1 __w)
    { 
        return;
    }
}

//--- bar.h
namespace std 
{
  template<typename... _Types>
    struct _Traits
    {
      static constexpr bool _S_copy_ctor =
   (__is_trivial(_Types) && ...);
    };

  template<typename... _Types>
    struct variant
    {
      void
      swap(variant& __rhs)
      noexcept((__is_trivial(_Types) && ...))
      {
      }
    };
}

//--- a.cppm
module;
#include "foo.h"
#include "bar.h"
export module a;

//--- b.cppm
// expected-no-diagnostics
module;
#include "bar.h"
export module b;
import a;

The command line:

clang++ -std=c++20 a.cppm --precompile -o a.pcm
clang++ -std=c++20 b.cppm -fmodule-file=a=a.pcm --precompile -o b.pcm

Then we will see:

error: 'std::_Traits' has different definitions in different modules; first difference is defined here found data member '_S_copy_ctor' with an initializer
      static constexpr bool _S_copy_ctor =
      ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
note: but in 'a.<global>' found data member '_S_copy_ctor' with a different initializer
      static constexpr bool _S_copy_ctor =
      ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
error: 'std::variant::swap' from module 'a.<global>' is not present in definition of 'variant<_Types...>' provided earlier
      swap(variant& __rhs)
      ^
note: declaration of 'swap' does not match

The confusing part is that the error is gone after we remove the seemingly meaningless foo.h.

@ChuanqiXu9 ChuanqiXu9 added the clang:modules C++20 modules and Clang Header Modules label Mar 3, 2023
@ChuanqiXu9 ChuanqiXu9 self-assigned this Mar 3, 2023
@llvmbot
Copy link
Member

llvmbot commented Mar 3, 2023

@llvm/issue-subscribers-clang-modules

@ChuanqiXu9 ChuanqiXu9 added the invalid Resolved as invalid, i.e. not a bug label Mar 6, 2023
@ChuanqiXu9
Copy link
Member Author

Oh, this is an invalid example. The operator && in module a is different from the operator && in module b due to the operator defined in foo.h. So the result of the ODR checking is correct but maybe it need to be more friendly.

@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2023
ChuanqiXu9 added a commit that referenced this issue Mar 6, 2023
Address #61150.

The test is intended to show the polluted operator&& will affect the ODR
checking and the ODR checking here is correct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules invalid Resolved as invalid, i.e. not a bug
Projects
None yet
Development

No branches or pull requests

3 participants