Skip to content

[C++20][Modules] error: 'std::align_val_t' has different definitions in different modules #76638

Closed
@Ivan171

Description

@Ivan171

I could not create a minimal reproducer, but I've attached the preprocessed files, which I think is enough to reproduce the issue.

Environment

Windows 10
Clang 18.0.0git (https://github.com/llvm/llvm-project 85c3953)
MSVC 2022 (17.8.1)

Reproducer

// mod2.cpp

module;

#include <utility>

export module mod2;
// mod1.cpp

module;

#include <memory>

export module mod1;

import mod2;
$ clang++.exe -std=c++20 -fno-delayed-template-parsing -fno-ms-compatibility -x c++-module mod2.cpp --precompile
$ clang++.exe -std=c++20 -fno-delayed-template-parsing -fno-ms-compatibility -x c++-module mod1.cpp -fprebuilt-module-path=.
In file included from mod1.cpp:3:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 2022\VC\Tools\MSVC\14.38.33130\include\memory:10:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 2022\VC\Tools\MSVC\14.38.33130\include\exception:8:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 2022\VC\Tools\MSVC\14.38.33130\include\yvals.h:20:
In file included from C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt\crtdbg.h:13:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 2022\VC\Tools\MSVC\14.38.33130\include\vcruntime_new_debug.h:10:
[repro.zip](https://github.com/llvm/llvm-project/files/13799238/repro.zip)
[repro.zip](https://github.com/llvm/llvm-project/files/13799246/repro.zip)

C:\Program Files (x86)\Microsoft Visual Studio 2022\VC\Tools\MSVC\14.38.33130\include\vcruntime_new.h:27:16: error: 'std::align_val_t'
      has different definitions in different modules; defined here first difference is enum with specified type 'size_t'
      (aka 'unsigned long long')
   27 |     enum class align_val_t : size_t {};
      |     ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files (x86)\Microsoft Visual Studio 2022\VC\Tools\MSVC\14.38.33130\include\vcruntime_new.h:27:16: note: but in
      'mod2.<global>' found enum with specified type 'size_t' (aka 'unsigned long long')
   27 |     enum class align_val_t : size_t {};
      |     ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Activity

Ivan171

Ivan171 commented on Dec 30, 2023

@Ivan171
Author
llvmbot

llvmbot commented on Dec 30, 2023

@llvmbot
Member

@llvm/issue-subscribers-clang-modules

Author: Ivan171 (Ivan171)

I could not create a minimal reproducer, but I've attached the preprocessed files, which I think is enough to reproduce the issue.

Environment

Windows 10
Clang 18.0.0git (https://github.com/llvm/llvm-project 85c3953)
MSVC 2022 (17.8.1)

Reproducer

// mod2.cpp

module;

#include &lt;utility&gt;

export module mod2;
// mod1.cpp

module;

#include &lt;memory&gt;

export module mod1;

import mod2;
$ clang++.exe -std=c++20 -fno-delayed-template-parsing -fno-ms-compatibility -x c++-module mod2.cpp --precompile
$ clang++.exe -std=c++20 -fno-delayed-template-parsing -fno-ms-compatibility -x c++-module mod1.cpp -fprebuilt-module-path=.
In file included from mod1.cpp:3:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 2022\VC\Tools\MSVC\14.38.33130\include\memory:10:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 2022\VC\Tools\MSVC\14.38.33130\include\exception:8:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 2022\VC\Tools\MSVC\14.38.33130\include\yvals.h:20:
In file included from C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt\crtdbg.h:13:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 2022\VC\Tools\MSVC\14.38.33130\include\vcruntime_new_debug.h:10:
[repro.zip](https://github.com/llvm/llvm-project/files/13799238/repro.zip)
[repro.zip](https://github.com/llvm/llvm-project/files/13799246/repro.zip)

C:\Program Files (x86)\Microsoft Visual Studio 2022\VC\Tools\MSVC\14.38.33130\include\vcruntime_new.h:27:16: error: 'std::align_val_t'
      has different definitions in different modules; defined here first difference is enum with specified type 'size_t'
      (aka 'unsigned long long')
   27 |     enum class align_val_t : size_t {};
      |     ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files (x86)\Microsoft Visual Studio 2022\VC\Tools\MSVC\14.38.33130\include\vcruntime_new.h:27:16: note: but in
      'mod2.&lt;global&gt;' found enum with specified type 'size_t' (aka 'unsigned long long')
   27 |     enum class align_val_t : size_t {};
      |     ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
koplas

koplas commented on Jan 1, 2024

@koplas
Contributor

Does compiling with -fms-compatibility yield the same error?

Ivan171

Ivan171 commented on Jan 2, 2024

@Ivan171
Author

Does compiling with -fms-compatibility yield the same error?

Yes

ChuanqiXu9

ChuanqiXu9 commented on Jan 2, 2024

@ChuanqiXu9
Member

Oh, sad. This has the same error message with #60027...

koplas

koplas commented on Jan 2, 2024

@koplas
Contributor

Here is a reduced reproducer:

// mod1.cpp
module;

extern "C" {
    typedef unsigned __int64 size_t;
}


namespace std {
    enum class align_val_t : size_t {};
}


export module mod1;

import mod2;
// mod2.cpp
module;

extern "C" {
    typedef unsigned __int64 size_t;
 }


namespace std {
            using :: size_t;
}


extern "C++" {
    namespace std {
        enum class align_val_t : size_t {};
    }
}

export module mod2;

Seems similar to the reproducer provided by @davidstone: #60027 (comment)

self-assigned this
on Jan 3, 2024
ChuanqiXu9

ChuanqiXu9 commented on Jan 8, 2024

@ChuanqiXu9
Member

This is slightly more tricky than I thought.

The reduced example can be accepted by using the canonical decl for the integral type for enum decl here:

if (Enum->getIntegerTypeSourceInfo())
AddQualType(Enum->getIntegerType());

However, this may introduce false-negative issues. Now the following case will be accepted:

// mod1.cpp
module;

extern "C" {
    typedef unsigned __int64 size_t;
}


namespace std {
    enum class align_val_t : size_t {};
}
export module mod1;

import mod2;
// mod2.cpp
module;

extern "C" {
    typedef unsigned __int64 size_t;
 }


namespace std {
            using :: size_t;
}


extern "C++" {
    namespace std {
        enum class align_val_t : std::size_t {};
    }
}

export module mod2;

Now the spellings of the definition of align_val_t in two different modules are different. This violates http://eel.is/c++draft/basic.def.odr#14.4:

Each such definition shall consist of the same sequence of tokens


Also my "fix" only works for the reported enum case, but I believe the similar problem can occur in other places.

@zygoloid Can you take a look about how should we proceed here?

ChuanqiXu9

ChuanqiXu9 commented on Jan 15, 2024

@ChuanqiXu9
Member

Given the reported issue has a stronger impact (we've seen multiple reports about it) and the down side of the proposed solution may only be a concern, I'd like to land the proposed solution in a few days if no more comments come in.

11 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

clang:modulesC++20 modules and Clang Header Modules

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @Ivan171@EugeneZelenko@koplas@llvmbot@ChuanqiXu9

      Issue actions

        [C++20][Modules] error: 'std::align_val_t' has different definitions in different modules · Issue #76638 · llvm/llvm-project