[libcxx-commits] [libcxx] [libc++] Simplify std::launder (PR #147985)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 15 10:13:02 PDT 2025
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/147985
>From 6f3806ae738c6cd7bba4116c90d4d587a60b0787 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 10 Jul 2025 17:29:52 +0200
Subject: [PATCH 1/2] [libc++] Simplify std::launder
---
libcxx/include/__new/launder.h | 7 ++-----
.../support.dynamic/ptr.launder/launder.types.verify.cpp | 9 ++++-----
2 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/libcxx/include/__new/launder.h b/libcxx/include/__new/launder.h
index 83d80015913d9..df9adbff149df 100644
--- a/libcxx/include/__new/launder.h
+++ b/libcxx/include/__new/launder.h
@@ -10,8 +10,6 @@
#define _LIBCPP___NEW_LAUNDER_H
#include <__config>
-#include <__type_traits/is_function.h>
-#include <__type_traits/is_void.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -20,15 +18,14 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp>
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT {
- static_assert(!(is_function<_Tp>::value), "can't launder functions");
- static_assert(!is_void<_Tp>::value, "can't launder cv-void");
+ // The compiler diagnoses misuses of __builtin_launder, so we don't need to add any static_asserts.
return __builtin_launder(__p);
}
#if _LIBCPP_STD_VER >= 17
template <class _Tp>
[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp* launder(_Tp* __p) noexcept {
- return std::__launder(__p);
+ return __builtin_launder(__p);
}
#endif
_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp b/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp
index 4f2b627b8601a..5f6e53f98ad34 100644
--- a/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp
@@ -25,12 +25,11 @@ int main(int, char**) {
(void)std::launder((void*)nullptr);
(void)std::launder((const void*)nullptr);
(void)std::launder((volatile void*)nullptr);
- (void)std::launder(
- (const volatile void*)nullptr); // expected-error-re@*:* 4 {{static assertion failed{{.*}}can't launder cv-void}}
- // expected-error@*:* 0-4 {{void pointer argument to '__builtin_launder' is not allowed}}
+ (void)std::launder((const volatile void*)nullptr);
+ // expected-error@*:* 4 {{void pointer argument to '__builtin_launder' is not allowed}}
- (void)std::launder(foo); // expected-error-re@*:* 1 {{static assertion failed{{.*}}can't launder functions}}
- // expected-error@*:* 0-1 {{function pointer argument to '__builtin_launder' is not allowed}}
+ (void)std::launder(foo);
+ // expected-error@*:* 1 {{function pointer argument to '__builtin_launder' is not allowed}}
return 0;
}
>From 2f16bf5e1b53f0704d7f0041d158f3d5faaef710 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 15 Jul 2025 13:12:54 -0400
Subject: [PATCH 2/2] Update libcxx/include/__new/launder.h
---
libcxx/include/__new/launder.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/__new/launder.h b/libcxx/include/__new/launder.h
index df9adbff149df..886f614eed2e7 100644
--- a/libcxx/include/__new/launder.h
+++ b/libcxx/include/__new/launder.h
@@ -18,7 +18,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp>
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT {
- // The compiler diagnoses misuses of __builtin_launder, so we don't need to add any static_asserts.
+ // The compiler diagnoses misuses of __builtin_launder, so we don't need to add any static_asserts
+ // to implement the Mandates.
return __builtin_launder(__p);
}
More information about the libcxx-commits
mailing list