Skip to content

Commit 29cc80f

Browse files
authored
Fix issue with never-constexpr __construct_at in C++ < 20. (llvm#87403)
The application of constexpr to __construct_at triggers weird linker errors when building LLVM with modules enabled and C++ < 20. > ld.lld: error: undefined hidden symbol: void* std::__1::__voidify[abi:nn190000]<llvm::sys::ProcessStatistics>(llvm::sys::ProcessStatistics&) >>>> referenced by construct_at.h:52 (/usr/local/bin/../include/c++/v1/__memory/construct_at.h:52) >>>> Program.cpp.o:(llvm::sys::Wait(llvm::sys::ProcessInfo const&, std::__1::optional<unsigned int>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, std::__1::optional<llvm::sys::ProcessStatistics>*, bool)) in archive lib/libLLVMSupport.a I suspect this is related to undefined behavior caused by the fact that construct_at is never really constexpr (which is UB NDR). I'm unsure how to meaningfully write a test for this, as I haven't been able to trigger it in smaller unit tests
1 parent a671cee commit 29cc80f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

libcxx/include/__memory/construct_at.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp* construct_at(_Tp* __location, _Args&&... __
4444
#endif
4545

4646
template <class _Tp, class... _Args, class = decltype(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))>
47-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __construct_at(_Tp* __location, _Args&&... __args) {
47+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* __construct_at(_Tp* __location, _Args&&... __args) {
4848
#if _LIBCPP_STD_VER >= 20
4949
return std::construct_at(__location, std::forward<_Args>(__args)...);
5050
#else

0 commit comments

Comments
 (0)