Skip to content

Conversation

@philnik777
Copy link
Contributor

No description provided.

@philnik777 philnik777 marked this pull request as ready for review July 8, 2025 18:22
@philnik777 philnik777 requested a review from a team as a code owner July 8, 2025 18:22
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jul 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 8, 2025

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/147025.diff

1 Files Affected:

  • (modified) libcxx/include/__memory/construct_at.h (+4-7)
diff --git a/libcxx/include/__memory/construct_at.h b/libcxx/include/__memory/construct_at.h
index 21337e766b2d0..b64e64b5a29b0 100644
--- a/libcxx/include/__memory/construct_at.h
+++ b/libcxx/include/__memory/construct_at.h
@@ -12,14 +12,12 @@
 
 #include <__assert>
 #include <__config>
-#include <__iterator/access.h>
 #include <__memory/addressof.h>
 #include <__new/placement_new_delete.h>
 #include <__type_traits/enable_if.h>
 #include <__type_traits/is_array.h>
 #include <__utility/declval.h>
 #include <__utility/forward.h>
-#include <__utility/move.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -65,11 +63,10 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy_at(_Tp* __loc
 
 #if _LIBCPP_STD_VER >= 20
 template <class _Tp, __enable_if_t<is_array<_Tp>::value, int> = 0>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy_at(_Tp* __loc) {
+_LIBCPP_HIDE_FROM_ABI constexpr void __destroy_at(_Tp* __loc) {
   _LIBCPP_ASSERT_NON_NULL(__loc != nullptr, "null pointer given to destroy_at");
-  auto const __end = std::end(*__loc);
-  for (auto __it = std::begin(*__loc); __it != __end; ++__it)
-    std::__destroy_at(__it);
+  for (auto&& __val : *__loc)
+    std::__destroy_at(std::addressof(__val));
 }
 #endif
 
@@ -82,7 +79,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void destroy_at(_Tp* __loc)
 
 #  if _LIBCPP_STD_VER >= 20
 template <class _Tp, enable_if_t<is_array_v<_Tp>, int> = 0>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void destroy_at(_Tp* __loc) {
+_LIBCPP_HIDE_FROM_ABI constexpr void destroy_at(_Tp* __loc) {
   std::__destroy_at(__loc);
 }
 #  endif

Comment on lines +68 to +69
for (auto&& __val : *__loc)
std::__destroy_at(std::addressof(__val));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change requested. I still think we should destroy array elements in reversed order. LWG3889 was submitted for this. But that's not related to this PR yet.

@philnik777 philnik777 merged commit 30f8c64 into llvm:main Jul 10, 2025
132 of 136 checks passed
@philnik777 philnik777 deleted the simplify_destroy_at branch July 10, 2025 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants