[libcxx-commits] [libcxx] [z/OS][libc++] Guard to be used only when `align_val_t` is available (PR #114396)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 5 06:41:18 PST 2024


================
@@ -66,16 +66,14 @@ class __small_buffer {
     if constexpr (__fits_in_buffer<_Stored>) {
       return std::launder(reinterpret_cast<_Stored*>(__buffer_));
     } else {
-      byte* __allocation = static_cast<byte*>(::operator new[](sizeof(_Stored), align_val_t{alignof(_Stored)}));
-      std::construct_at(reinterpret_cast<byte**>(__buffer_), __allocation);
-      return std::launder(reinterpret_cast<_Stored*>(__allocation));
+      return static_cast<_Stored*>(std::__libcpp_allocate(_BufferSize * sizeof(byte), alignof(_Stored)));
----------------
ldionne wrote:

Ah, yes, my suggestion in https://github.com/llvm/llvm-project/pull/114396#discussion_r1828007471 was incorrect (it was based on the already incorrect diff). I think this is what we want (which is a mix between my suggestion and the status quo):

```c++
byte* __allocation = static_cast<byte*>(std::__libcpp_allocate(sizeof(_Stored), alignof(_Stored)));
std::construct_at(reinterpret_cast<byte**>(__buffer_), __allocation);
return std::launder(reinterpret_cast<_Stored*>(__allocation));
```

https://github.com/llvm/llvm-project/pull/114396


More information about the libcxx-commits mailing list