[libc-commits] [libc] [libc] Fix tuple std injection in userspace builds (PR #197605)
Schrodinger ZHU Yifan via libc-commits
libc-commits at lists.llvm.org
Thu May 14 22:11:29 PDT 2026
https://github.com/SchrodingerZhu updated https://github.com/llvm/llvm-project/pull/197605
>From 25cf9e1b7c8e8b874a6c80e320731625977c1012 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <i at zhuyi.fan>
Date: Wed, 13 May 2026 22:05:33 -0400
Subject: [PATCH 1/2] [libc] Fix tuple std injection in userspace builds
---
libc/src/__support/CPP/tuple.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/libc/src/__support/CPP/tuple.h b/libc/src/__support/CPP/tuple.h
index fa4fcd08cc04f..f3cac1b4b5781 100644
--- a/libc/src/__support/CPP/tuple.h
+++ b/libc/src/__support/CPP/tuple.h
@@ -125,7 +125,12 @@ LIBC_INLINE constexpr auto tuple_cat(const Tuples &...tuples) {
} // namespace LIBC_NAMESPACE_DECL
// Standard namespace definitions required for structured binding support.
+
+#ifdef _LIBCPP_BEGIN_NAMESPACE_STD
+_LIBCPP_BEGIN_NAMESPACE_STD
+#else
namespace std {
+#endif
template <class T> struct tuple_size;
template <size_t Idx, class T> struct tuple_element;
@@ -139,6 +144,10 @@ struct tuple_element<Idx, LIBC_NAMESPACE::cpp::tuple<Ts...>>
: LIBC_NAMESPACE::cpp::tuple_element<Idx,
LIBC_NAMESPACE::cpp::tuple<Ts...>> {};
+#ifdef _LIBCPP_END_NAMESPACE_STD
+_LIBCPP_END_NAMESPACE_STD
+#else
} // namespace std
+#endif
#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_TUPLE_H
>From 7293737a6c4eb10b582031d7b62a6522d738ab44 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <i at zhuyi.fan>
Date: Fri, 15 May 2026 01:11:17 -0400
Subject: [PATCH 2/2] avoid defining our tuple entirely when stl presents
---
libc/src/__support/CPP/tuple.h | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/libc/src/__support/CPP/tuple.h b/libc/src/__support/CPP/tuple.h
index f3cac1b4b5781..b25705b1e29fd 100644
--- a/libc/src/__support/CPP/tuple.h
+++ b/libc/src/__support/CPP/tuple.h
@@ -9,6 +9,16 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_TUPLE_H
#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_TUPLE_H
+#if __has_include(<tuple>)
+#include "src/__support/macros/config.h"
+#include <tuple> // NOLINT(llvmlibc-restrict-system-libc-headers)
+namespace LIBC_NAMESPACE_DECL {
+namespace cpp {
+template <typename... Ts>
+using tuple = std::tuple<Ts...>;
+}
+}
+#else
#include "src/__support/CPP/type_traits/decay.h"
#include "src/__support/CPP/utility/integer_sequence.h"
@@ -125,13 +135,9 @@ LIBC_INLINE constexpr auto tuple_cat(const Tuples &...tuples) {
} // namespace LIBC_NAMESPACE_DECL
// Standard namespace definitions required for structured binding support.
-
-#ifdef _LIBCPP_BEGIN_NAMESPACE_STD
-_LIBCPP_BEGIN_NAMESPACE_STD
-#else
namespace std {
-#endif
-
+// Add inline namespace as API tag for libc
+inline namespace LIBCLIBC_NAMESPACE_DECL {
template <class T> struct tuple_size;
template <size_t Idx, class T> struct tuple_element;
@@ -143,11 +149,8 @@ template <size_t Idx, typename... Ts>
struct tuple_element<Idx, LIBC_NAMESPACE::cpp::tuple<Ts...>>
: LIBC_NAMESPACE::cpp::tuple_element<Idx,
LIBC_NAMESPACE::cpp::tuple<Ts...>> {};
-
-#ifdef _LIBCPP_END_NAMESPACE_STD
-_LIBCPP_END_NAMESPACE_STD
-#else
+}
} // namespace std
-#endif
+#endif // __has_include(<tuple>)
#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_TUPLE_H
More information about the libc-commits
mailing list