From cc57a78190b8526e23e7979c5ef0859c2bb72366 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Fri, 26 Apr 2019 01:02:18 +0000 Subject: [PATCH] Fix return type of std::tuple_cat. When the arguments to tuple cat were const, the const was incorrectly propagated into the type of the resulting tuple. For example: const std::tuple t(42); auto r = std::tuple_cat(t, t); // Incorrect! should be std::tuple. static_assert(is_same_v>); git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@359255 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/tuple | 4 ++-- .../tuple.tuple/tuple.creation/tuple_cat.pass.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/tuple b/include/tuple index 335e59e67..7437d5c48 100644 --- a/include/tuple +++ b/include/tuple @@ -1211,7 +1211,7 @@ template struct __tuple_cat_return_1, true, _Tuple0> { typedef typename __tuple_cat_type, - typename __make_tuple_types::type>::type>::type + typename __make_tuple_types::type>::type>::type type; }; @@ -1220,7 +1220,7 @@ struct __tuple_cat_return_1, true, _Tuple0, _Tuple1, _Tuples... : public __tuple_cat_return_1< typename __tuple_cat_type< tuple<_Types...>, - typename __make_tuple_types::type>::type + typename __make_tuple_types::type>::type >::type, __tuple_like::type>::value, _Tuple1, _Tuples...> diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp index 40efbd1b8..5d5927d25 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp @@ -238,6 +238,21 @@ int main(int, char**) ); assert(t2 == std::make_tuple(std::make_tuple(1), std::make_tuple(2))); } + { + int x = 101; + std::tuple t(42, x, x, std::move(x)); + const auto& ct = t; + std::tuple t2(42, x, x); + const auto& ct2 = t2; + auto r = std::tuple_cat(std::move(t), std::move(ct), t2, ct2); + + ASSERT_SAME_TYPE(decltype(r), std::tuple< + int, int&, const int&, int&&, + int, int&, const int&, int&&, + int, int&, const int&, + int, int&, const int&>); + ((void)r); + } return 0; }