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

Đang mở
#1,647 8 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
build-system

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
C++
Star
1.9k
Fork
288
Merge trung bình
18 giờ 15 phút
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/cppwinrt

Tất cả issue của microsoft/cppwinrt

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.