Skip to content

Commit b48066f

Browse files
committed
[libcxx][modules] Fix missing includes for windows.
Previously, I was getting the following error when attempting to compile libc++ on windows with modules enabled. ``` While building module 'std': In file included from <module-includes>:1: In file included from gen/third_party/libc++/src/include/algorithm:1865: In file included from gen/third_party/libc++/src/include/__algorithm/inplace_merge.h:28: In file included from gen/third_party/libc++/src/include/__memory/unique_temporary_buffer.h:17: In file included from gen/third_party/libc++/src/include/__memory/allocator.h:19: gen/third_party/libc++/src/include/__new/allocate.h(40,73): error: declaration of 'align_val_t' must be imported from module 'sys_stage1.sysroot_vcruntime_new_h' before it is required 40 | return static_cast<_Tp*>(__builtin_operator_new(__size, static_cast<align_val... | ^ ../../third_party/depot_tools/win_toolchain/vs_files/e4305f407e/VC/Tools/MSVC/14.44.35207/include/vcruntime_new.h(27,33): note: declaration here is not visible 27 | _VCRT_EXPORT_STD enum class align_val_t : size_t {}; | ^ ``` I also received a similar error for `std::bad_alloc`. We have an include chain `__new/exceptions.h` => `__exception/exception.h` => `vcruntime_exception.h` => `vcruntime_new.h`. This means that it works fine with non-modules because `vcrunmite_exception.h` and `vcruntime_new.h` were both in the transitive includes. However, this fails with modules because `__new/exceptions.h` no longer exports symbols from `__exception/exception.h`, and thus `std::bad_alloc` and `std::align_val_t` are no longer visible.
1 parent e79f451 commit b48066f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

libcxx/include/__new/align_val_t.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
# pragma GCC system_header
1717
#endif
1818

19+
// <vcruntime_exception.h> defines its own std::align_val_t type,
20+
// which we use in order to be ABI-compatible with other STLs on Windows.
21+
#if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION && defined(_LIBCPP_ABI_VCRUNTIME)
22+
# include <vcruntime_new.h>
23+
#endif
24+
1925
_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
2026
#if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION && !defined(_LIBCPP_ABI_VCRUNTIME)
2127
# ifndef _LIBCPP_CXX03_LANG

libcxx/include/__new/exceptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
# pragma GCC system_header
1818
#endif
1919

20+
// <vcruntime_exception.h> defines its own std::bad_alloc type,
21+
// which we use in order to be ABI-compatible with other STLs on Windows.
22+
#if defined(_LIBCPP_ABI_VCRUNTIME)
23+
# include <vcruntime_exception.h>
24+
#endif
25+
2026
_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
2127
#if !defined(_LIBCPP_ABI_VCRUNTIME)
2228

0 commit comments

Comments
 (0)