Skip to content

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

Closed as not planned
@ChuanqiXu9

Description

@ChuanqiXu9

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.

Metadata

Metadata

Assignees

Labels

clang:modulesC++20 modules and Clang Header ModulesinvalidResolved as invalid, i.e. not a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions