[libcxx-commits] [libcxx] [libc++] Make __has_array_cookie a variable template (PR #212767)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 29 06:20:58 PDT 2026
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/212767
Using variable templates is slightly faster to compile and more readable, so we might as well use them.
>From da6ce638377adb574f5f220584d2535eda4f62df Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Wed, 29 Jul 2026 15:20:19 +0200
Subject: [PATCH] [libc++] Make __has_array_cookie a variable template
---
libcxx/include/__memory/array_cookie.h | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/libcxx/include/__memory/array_cookie.h b/libcxx/include/__memory/array_cookie.h
index be59f365aa80c..1869ef0244489 100644
--- a/libcxx/include/__memory/array_cookie.h
+++ b/libcxx/include/__memory/array_cookie.h
@@ -14,9 +14,7 @@
#include <__configuration/abi.h>
#include <__cstddef/size_t.h>
#include <__memory/addressof.h>
-#include <__type_traits/integral_constant.h>
#include <__type_traits/is_trivially_destructible.h>
-#include <__type_traits/negation.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -37,10 +35,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// TODO: We should factor in the choice of the usual deallocation function in this determination:
// a cookie may be available in more cases but we ignore those for now.
template <class _Tp>
-struct __has_array_cookie : _Not<is_trivially_destructible<_Tp> > {};
+inline const bool __has_array_cookie_v = !is_trivially_destructible<_Tp>::value;
#else
template <class _Tp>
-struct __has_array_cookie : false_type {};
+inline const bool __has_array_cookie_v = false;
#endif
struct __itanium_array_cookie {
@@ -97,7 +95,7 @@ template <class _Tp>
// Avoid failures when -fsanitize-address-poison-custom-array-cookie is enabled
_LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_SANITIZE("address") size_t __get_array_cookie([[__maybe_unused__]] _Tp const* __ptr) {
static_assert(
- __has_array_cookie<_Tp>::value, "Trying to access the array cookie of a type that is not guaranteed to have one");
+ __has_array_cookie_v<_Tp>, "Trying to access the array cookie of a type that is not guaranteed to have one");
#if defined(_LIBCPP_ABI_ITANIUM)
using _ArrayCookie = __itanium_array_cookie;
More information about the libcxx-commits
mailing list