Bug: Standard library headers included inside module purview of `winrt_numerics.ixx`

未关闭
#1,647 8 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp
领域
build-system

调研方向

Start with winrt_numerics.ixx and windowsnumerics.impl.h, then inspect the WindowsNumerics.inl includes in the Windows SDK and the mingw-w64 headers named in the report. Reproduce the module build with GCC or Clang and compare it with MSVC. Done when required standard headers are included in the global module fragment and the DirectX interop functions are exported, with the reported module conflicts resolved.

由索引模型根据 Issue 内容生成。

描述

Version

3.0.260818.1

Summary

In C++20 module builds (-modules), winrt_numerics.ixx only pre-includes <directxmath.h> in its global module fragment before declaring export module winrt_numerics; and including <windowsnumerics.impl.h> inside the module purview.

However, <windowsnumerics.impl.h> transitively includes standard library headers (<stdexcept> and <limits> via WindowsNumerics.inl in the Windows SDK, and <algorithm> and <cmath> in mingw-w64). Because those headers are not pre-included in the global module fragment, they are expanded directly inside the purview of winrt_numerics:

  • GCC (libstdc++) and Clang (libc++) attach those standard library declarations to the named module winrt_numerics, conflicting with earlier global module declarations from <version> and causing winrt_numerics.ixx to fail to compile.
  • MSVC masks this only because its standard library headers wrap namespace std in extern "C++", and winrt_numerics.ixx suppresses warning '#include <stdexcept>' in the purview of module 'winrt_numerics' appears erroneous with #pragma warning(disable : 5244).

In addition, the DirectX interop functions (XMLoadFloat2, XMStoreFloat2, etc.) in <windowsnumerics.impl.h> are declared outside _WINDOWS_NUMERICS_BEGIN_NAMESPACE_, leaving them unexported and attached to winrt_numerics even on MSVC.

Reproducible example
$out = Join-Path $env:TEMP "cppwinrt_numerics_repro"
Remove-Item -Recurse -Force $out -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Force -Path $out | Out-Null
Push-Location $out

# 1. Generate module projection with cppwinrt 3.0.260818.1
$cppwinrt = "$env:USERPROFILE\.nuget\packages\microsoft.windows.cppwinrt\3.0.260818.1\bin\cppwinrt.exe"
& $cppwinrt -in local -out $out -modules -include Windows.Foundation

# 2. MSVC: succeeds because warning C5244 is suppressed and MSVC STL uses extern "C++"
$vsDevCmd = "C:\Program Files\Microsoft Visual Studio\18\Community\Common7\Tools\VsDevCmd.bat"
$msvcCmds = @(
    "`"$vsDevCmd`" -arch=x64 -no_logo"
    "cd /d `"$out`""
    "cl /nologo /std:c++20 /EHsc /MD /I. /c /interface /TP winrt/winrt_numerics.ixx /ifcOutput winrt_numerics.ifc"
) -join " && "
cmd /c $msvcCmds

# 3. GCC: fails when compiling winrt/winrt_numerics.ixx directly
g++ -std=c++20 -fmodules -I. -x c++ -c winrt/winrt_numerics.ixx -o winrt_numerics.o

Pop-Location

MSVC output:

winrt_numerics.ixx

GCC output when compiling winrt/winrt_numerics.ixx:

In file included from C:/Tools/msys64/ucrt64/include/c++/16.2.0/bits/stl_algobase.h:63,
                 from C:/Tools/msys64/ucrt64/include/c++/16.2.0/algorithm:62,
                 from C:/Tools/msys64/ucrt64/include/windowsnumerics.impl.h:28,
                 from winrt/winrt_numerics.ixx:48:
C:/Tools/msys64/ucrt64/include/c++/16.2.0/bits/stl_pair.h:102:12: error: conflicting declaration of 'struct std::_Index_tuple<_Indexes>' in module 'winrt_numerics'
  102 |     struct _Index_tuple;
      |            ^~~~~~~~~~~~
In file included from C:/Tools/msys64/ucrt64/include/c++/16.2.0/bits/cpp_type_traits.h:42,
                 from C:/Tools/msys64/ucrt64/include/c++/16.2.0/bits/stl_algobase.h:60:
C:/Tools/msys64/ucrt64/include/c++/16.2.0/type_traits:4372:39: note: previously declared in global module
 4372 |   template<size_t... _Indexes> struct _Index_tuple { };
      |                                       ^~~~~~~~~~~~
In file included from C:/Tools/msys64/ucrt64/include/c++/16.2.0/cmath:55,
                 from C:/Tools/msys64/ucrt64/include/windowsnumerics.impl.h:29:
C:/Tools/msys64/ucrt64/include/math.h:150:10: error: conflicting declaration of 'struct _exception' in global module
  150 |   struct _exception {
      |          ^~~~~~~~~~
C:/Tools/msys64/ucrt64/include/math.h:15:8: note: previously declared in module 'winrt_numerics'
   15 | struct _exception;
      |        ^~~~~~~~~~
Expected behavior

Pre-include the standard library headers required by <windowsnumerics.impl.h> in the global module fragment of winrt_numerics.ixx (or import std; before including <windowsnumerics.impl.h>), and ensure the DirectX interop functions in <windowsnumerics.impl.h> are also exported with WINRT_EXPORT.

Actual behavior

No response

Additional comments

No response

主要语言
C++
星标
1.9k
派生
288
平均合并
18 小时 15 分钟
30 天内合并 PR
2

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/cppwinrt 的其他 Issue

查看 microsoft/cppwinrt 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。