[libcxx-commits] [libcxx] [libc++] P2255R2: Add deleted tuple constructor overloads (PR #205379)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 10 04:19:52 PDT 2026
================
@@ -0,0 +1,74 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++23
+
+// <tuple>
+
+// tuple(UTypes&&... u);
+// tuple(tuple<UTypes...>& u);
+// tuple(const tuple<UTypes...>& u);
+// tuple(tuple<UTypes...>&& u);
+// tuple(const tuple<UTypes...>&& u);
+// tuple(pair<U1, U2>& u);
+// tuple(const pair<U1, U2>& u);
+// tuple(pair<U1, U2>&& u);
+// tuple(const pair<U1, U2>&& u);
+//
+// The constructors above are defined as deleted if reference_constructs_from_temporary_v
+// is true for one of the corresponding tuple elements.
+
+#include <memory>
+#include <tuple>
+#include <type_traits>
+#include <utility>
+
+struct X {
+ X(int);
+};
+
+static_assert(std::is_constructible_v<std::tuple<const X&>, X&>);
+static_assert(!std::is_constructible_v<std::tuple<const X&>, int>);
+static_assert(!std::is_constructible_v<std::tuple<const X&>, std::tuple<int>&>);
+static_assert(!std::is_constructible_v<std::tuple<const X&>, const std::tuple<int>&>);
+static_assert(!std::is_constructible_v<std::tuple<const X&>, std::tuple<int>&&>);
+static_assert(!std::is_constructible_v<std::tuple<const X&>, const std::tuple<int>&&>);
+static_assert(!std::is_constructible_v<std::tuple<const X&, int>, std::pair<int, int>&>);
+static_assert(!std::is_constructible_v<std::tuple<const X&, int>, const std::pair<int, int>&>);
+static_assert(!std::is_constructible_v<std::tuple<const X&, int>, std::pair<int, int>&&>);
+static_assert(!std::is_constructible_v<std::tuple<const X&, int>, const std::pair<int, int>&&>);
+
+void test() {
+ std::allocator<int> alloc;
+ std::tuple<int> t(1);
+ const std::tuple<int> ct(1);
+ std::pair<int, int> p(1, 2);
+ const std::pair<int, int> cp(1, 2);
+
+ // expected-error-re@*:* 18 {{call to deleted constructor of 'std::tuple<{{.*}}>'}}
----------------
philnik777 wrote:
If you can craft such a test we can certainly add it. My point is that we're allowed to do it either way assuming we're constraining correctly. It may be difficult to constrain correctly, but not forbidden, so we should use SFINAE tests instead of `.verify.cpp` tests.
https://github.com/llvm/llvm-project/pull/205379
More information about the libcxx-commits
mailing list