[libcxx-commits] [libcxx] 29cc80f - Fix issue with never-constexpr __construct_at in C++ < 20. (#87403)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 5 09:16:20 PDT 2024


Author: Eric
Date: 2024-04-05T12:16:17-04:00
New Revision: 29cc80f4ecafe45586401ce4a79b324b6240b6e9

URL: https://github.com/llvm/llvm-project/commit/29cc80f4ecafe45586401ce4a79b324b6240b6e9
DIFF: https://github.com/llvm/llvm-project/commit/29cc80f4ecafe45586401ce4a79b324b6240b6e9.diff

LOG: Fix issue with never-constexpr __construct_at in C++ < 20. (#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

Added: 
    

Modified: 
    libcxx/include/__memory/construct_at.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__memory/construct_at.h b/libcxx/include/__memory/construct_at.h
index 91d17134db0141..eb021324800644 100644
--- a/libcxx/include/__memory/construct_at.h
+++ b/libcxx/include/__memory/construct_at.h
@@ -44,7 +44,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp* construct_at(_Tp* __location, _Args&&... __
 #endif
 
 template <class _Tp, class... _Args, class = decltype(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __construct_at(_Tp* __location, _Args&&... __args) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* __construct_at(_Tp* __location, _Args&&... __args) {
 #if _LIBCPP_STD_VER >= 20
   return std::construct_at(__location, std::forward<_Args>(__args)...);
 #else


        


More information about the libcxx-commits mailing list