Skip to content

Commit

Permalink
[memory] clang-18 workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkaratarakis committed Jun 17, 2024
1 parent d19efd1 commit bba857c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions include/fixed_containers/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ namespace fixed_containers::memory
{
// Similar to https://en.cppreference.com/w/cpp/memory/construct_at
// but uses references and correctly handles types that overload operator&
//
// Returning `auto` has issues with clang-18 - causes a compiler crash.
// One bug is: https://github.com/llvm/llvm-project/issues/92680
// There appears to be more, to be investigated.
// Returning an explicit `T*` also fails in certain cases (msvc).
// As a workaround, don't return anything, which is a minor divergence with `std::construct_at()`.
template <typename T, typename ... Args>
constexpr auto construct_at_address_of(T& p, Args&&... args)
constexpr void construct_at_address_of(T& p, Args&&... args)
{
return std::construct_at(std::addressof(p), std::forward<Args>(args)...);
std::construct_at(std::addressof(p), std::forward<Args>(args)...);
}

// Similar to https://en.cppreference.com/w/cpp/memory/destroy_at
Expand Down
2 changes: 2 additions & 0 deletions test/memory_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ TEST(ConstructAtAddressOf, CArray)
#if !defined(_MSC_VER)
int a[5]{};
memory::destroy_at_address_of(a);
#if 0
int* result = memory::construct_at_address_of(a);
result[0] = 99;
ASSERT_TRUE(result == static_cast<int*>(a));
#endif
#endif
}
} // namespace fixed_containers

0 comments on commit bba857c

Please sign in to comment.