无法在带有 Clang 的模块中使用对齐的“operator new”

Unable to use aligned `operator new` in a module with Clang

我正在试验 Clang "modules" 功能,我正在尝试编译以下代码:

export module a;

#include <new>

export void *foo()
{
    return ::operator new(1, std::align_val_t(1));
}

export int main() {}

Try it live

当我尝试 clang++ -std=c++2a -pedantic-errors -fmodules-ts --precompile -x c++-module a.cpp -o a.pcm 时,我得到了

error: ISO C++ requires a definition in this translation unit for function 'operator new'
 because its type does not have linkage [-Werror,-Wundefined-internal-type]
a.cpp:7:14: note: used here
    return ::operator new(1, std::align_val_t(1));
         ^
1 error generated.

删除 -pedantic-errors 修复了错误,但是当我尝试使用 clang++ -std=c++2a -fmodules-ts a.pcm -o a.exe link 生成的模块时,我得到

Z:\Lander\msys2\tmp\a-cfaf65.o:a.pcm:(.text+0x10): undefined reference to
 `_ZnwyW1aESt11align_val_t'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

特别烦人,因为 <iostream>(间接)似乎依赖于对齐的 operator new,所以我也不能在模块中使用它。以及其他一些标准 headers.

这是怎么回事?

这是一个 Clang 错误,我该如何解决它?


我的Clang是MSYS2提供的最新版本:

# clang++ --version
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-w64-windows-gnu
Thread model: posix

编辑:

归档a bug report,让我们看看会发生什么...

标准库不是您的模块的一部分 a。所以不要在 export module a; 之后包含 header。包括之前的 header。