From: Ville Voutilainen Date: Mon, 21 Dec 2015 11:22:16 +0000 (+0200) Subject: re PR libstdc++/66693 ([C++17] std::tuple_size fails with const std::array) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=de0830e12b6a990e8b0f4f43aca03440f8cd6f2f;p=gcc.git re PR libstdc++/66693 ([C++17] std::tuple_size fails with const std::array) PR libstdc++/66693. * include/std/tuple (tuple_element, tuple_size, tuple_element_t, __tuple_element_t): Move to... * include/std/utility: ...here. * testsuite/20_util/pair/astuple/astuple.cc: Adjust. * testsuite/20_util/pair/astuple/astuple_cpp14.cc: New. * testsuite/20_util/tuple/tuple_element.cc: Adjust. * testsuite/20_util/tuple/tuple_element_t.cc: Likewise. * testsuite/20_util/tuple/tuple_size.cc: Likewise. * testsuite/23_containers/array/tuple_interface/tuple_element.cc: Likewise. * testsuite/23_containers/array/tuple_interface/tuple_element_cpp14.cc: New. * testsuite/23_containers/array/tuple_interface/tuple_size.cc: Adjust. From-SVN: r231875 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c4f9f3c2e0a..1a79ff8212e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,20 @@ +2015-12-21 Ville Voutilainen + + PR libstdc++/66693 + * include/std/tuple (tuple_element, tuple_size, tuple_element_t, + __tuple_element_t): Move to... + * include/std/utility: ...here. + * testsuite/20_util/pair/astuple/astuple.cc: Adjust. + * testsuite/20_util/pair/astuple/astuple_cpp14.cc: New. + * testsuite/20_util/tuple/tuple_element.cc: Adjust. + * testsuite/20_util/tuple/tuple_element_t.cc: Likewise. + * testsuite/20_util/tuple/tuple_size.cc: Likewise. + * testsuite/23_containers/array/tuple_interface/tuple_element.cc: + Likewise. + * testsuite/23_containers/array/tuple_interface/tuple_element_cpp14.cc: + New. + * testsuite/23_containers/array/tuple_interface/tuple_size.cc: Adjust. + 2015-12-18 Ville Voutilainen Fix a regression introduced by the fix of libstdc++/68276. diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index e6c32b348be..78f58b4ce43 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -1197,10 +1197,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; - /// Gives the type of the ith element of a given tuple type. - template - struct tuple_element; - /** * Recursive case for tuple_element: strip off the first element in * the tuple and retrieve the (i-1)th element of the remaining tuple. @@ -1218,53 +1214,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef _Head type; }; - // Duplicate of C++14's tuple_element_t for internal use in C++11 mode - template - using __tuple_element_t = typename tuple_element<__i, _Tp>::type; - - template - struct tuple_element<__i, const _Tp> - { - typedef typename add_const<__tuple_element_t<__i, _Tp>>::type type; - }; - - template - struct tuple_element<__i, volatile _Tp> - { - typedef typename add_volatile<__tuple_element_t<__i, _Tp>>::type type; - }; - - template - struct tuple_element<__i, const volatile _Tp> - { - typedef typename add_cv<__tuple_element_t<__i, _Tp>>::type type; - }; - -#if __cplusplus > 201103L -#define __cpp_lib_tuple_element_t 201402 - - template - using tuple_element_t = typename tuple_element<__i, _Tp>::type; -#endif - - /// Finds the size of a given tuple type. - template - struct tuple_size; - - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 2313. tuple_size should always derive from integral_constant - template - struct tuple_size - : integral_constant::value> { }; - - template - struct tuple_size - : integral_constant::value> { }; - - template - struct tuple_size - : integral_constant::value> { }; - /// class tuple_size template struct tuple_size> diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility index 985bcb20215..2115d73cac6 100644 --- a/libstdc++-v3/include/std/utility +++ b/libstdc++-v3/include/std/utility @@ -79,11 +79,56 @@ namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION - template - class tuple_size; + /// Finds the size of a given tuple type. + template + struct tuple_size; + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2313. tuple_size should always derive from integral_constant + template + struct tuple_size + : integral_constant::value> { }; + + template + struct tuple_size + : integral_constant::value> { }; + + template + struct tuple_size + : integral_constant::value> { }; + + /// Gives the type of the ith element of a given tuple type. + template + struct tuple_element; + + // Duplicate of C++14's tuple_element_t for internal use in C++11 mode + template + using __tuple_element_t = typename tuple_element<__i, _Tp>::type; + + template + struct tuple_element<__i, const _Tp> + { + typedef typename add_const<__tuple_element_t<__i, _Tp>>::type type; + }; + + template + struct tuple_element<__i, volatile _Tp> + { + typedef typename add_volatile<__tuple_element_t<__i, _Tp>>::type type; + }; - template - class tuple_element; + template + struct tuple_element<__i, const volatile _Tp> + { + typedef typename add_cv<__tuple_element_t<__i, _Tp>>::type type; + }; + +#if __cplusplus > 201103L +#define __cpp_lib_tuple_element_t 201402 + + template + using tuple_element_t = typename tuple_element<__i, _Tp>::type; +#endif template struct __is_tuple_like_impl : false_type diff --git a/libstdc++-v3/testsuite/20_util/pair/astuple/astuple.cc b/libstdc++-v3/testsuite/20_util/pair/astuple/astuple.cc index 11e3fce2411..15ab87210ef 100644 --- a/libstdc++-v3/testsuite/20_util/pair/astuple/astuple.cc +++ b/libstdc++-v3/testsuite/20_util/pair/astuple/astuple.cc @@ -24,6 +24,10 @@ typedef std::pair test_type; static_assert( std::tuple_size::value == 2, "size is 2" ); +static_assert( std::tuple_size::value == 2, "size is 2" ); +static_assert( std::tuple_size::value == 2, "size is 2" ); +static_assert( std::tuple_size::value == 2, + "size is 2" ); template using Tuple_elt = typename std::tuple_element::type; @@ -35,3 +39,27 @@ static_assert( is_same, test_type::first_type>::value, static_assert( is_same, test_type::second_type>::value, "second type is long" ); + +static_assert( is_same, + const test_type::first_type>::value, + "first type is const int" ); + +static_assert( is_same, + const test_type::second_type>::value, + "second type is const long" ); + +static_assert( is_same, + volatile test_type::first_type>::value, + "first type is volatile int" ); + +static_assert( is_same, + volatile test_type::second_type>::value, + "second type is volatile long" ); + +static_assert( is_same, + const volatile test_type::first_type>::value, + "first type is const volatile int" ); + +static_assert( is_same, + const volatile test_type::second_type>::value, + "second type is const volatile long" ); diff --git a/libstdc++-v3/testsuite/20_util/pair/astuple/astuple_cpp14.cc b/libstdc++-v3/testsuite/20_util/pair/astuple/astuple_cpp14.cc new file mode 100644 index 00000000000..9a0a3e52701 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/astuple/astuple_cpp14.cc @@ -0,0 +1,59 @@ +// { dg-do compile } +// { dg-options "-std=gnu++14" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +typedef std::pair test_type; + +template + using Tuple_elt = std::tuple_element_t; + +using std::is_same; + +static_assert( is_same, test_type::first_type>::value, + "first type is int" ); + +static_assert( is_same, test_type::second_type>::value, + "second type is long" ); + +static_assert( is_same, + const test_type::first_type>::value, + "first type is const int" ); + +static_assert( is_same, + const test_type::second_type>::value, + "second type is const long" ); + +static_assert( is_same, + volatile test_type::first_type>::value, + "first type is volatile int" ); + +static_assert( is_same, + volatile test_type::second_type>::value, + "second type is volatile long" ); + +static_assert( is_same, + const volatile test_type::first_type>::value, + "first type is const volatile int" ); + +static_assert( is_same, + const volatile test_type::second_type>::value, + "second type is const volatile long" ); diff --git a/libstdc++-v3/testsuite/20_util/tuple/tuple_element.cc b/libstdc++-v3/testsuite/20_util/tuple/tuple_element.cc index 78231cb1a11..9e6224ced7f 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/tuple_element.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/tuple_element.cc @@ -35,4 +35,10 @@ main() foo q1; tuple_element<0,tuple >::type q2(q1); tuple_element<2,tuple >::type q3(q1); + tuple_element<0,const tuple >::type q4(q1); + tuple_element<2,const tuple >::type q5(q1); + tuple_element<0,volatile tuple >::type q6(q1); + tuple_element<2,volatile tuple >::type q7(q1); + tuple_element<0,const volatile tuple >::type q8(q1); + tuple_element<2,const volatile tuple >::type q9(q1); } diff --git a/libstdc++-v3/testsuite/20_util/tuple/tuple_element_t.cc b/libstdc++-v3/testsuite/20_util/tuple/tuple_element_t.cc index 481666b3805..079e7f9879c 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/tuple_element_t.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/tuple_element_t.cc @@ -33,4 +33,10 @@ main() foo q1; tuple_element_t<0,tuple > q2(q1); tuple_element_t<2,tuple > q3(q1); + tuple_element_t<0,const tuple > q4(q1); + tuple_element_t<2,const tuple > q5(q1); + tuple_element_t<0,volatile tuple > q6(q1); + tuple_element_t<2,volatile tuple > q7(q1); + tuple_element_t<0,const volatile tuple > q8(q1); + tuple_element_t<2,const volatile tuple > q9(q1); } diff --git a/libstdc++-v3/testsuite/20_util/tuple/tuple_size.cc b/libstdc++-v3/testsuite/20_util/tuple/tuple_size.cc index 98b2477e585..d6f6ec5c503 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/tuple_size.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/tuple_size.cc @@ -1,3 +1,4 @@ +// { dg-do compile } // { dg-options "-std=gnu++11" } // Copyright (C) 2007-2015 Free Software Foundation, Inc. @@ -29,10 +30,28 @@ main() { bool test __attribute__((unused)) = true; - VERIFY(tuple_size >::value == 0); - VERIFY(tuple_size >::value == 1); - VERIFY(tuple_size >::value == 1); + static_assert(tuple_size>::value == 0, ""); + static_assert(tuple_size>::value == 1, ""); + static_assert(tuple_size>::value == 1, ""); typedef tuple test_tuple1; - VERIFY(tuple_size::value == 3); - VERIFY(tuple_size > >::value == 1); + static_assert(tuple_size::value == 3, ""); + static_assert(tuple_size>>::value == 1, ""); + + static_assert(tuple_size>::value == 0, ""); + static_assert(tuple_size>::value == 1, ""); + static_assert(tuple_size>::value == 1, ""); + static_assert(tuple_size::value == 3, ""); + static_assert(tuple_size>>::value == 1, ""); + + static_assert(tuple_size>::value == 0, ""); + static_assert(tuple_size>::value == 1, ""); + static_assert(tuple_size>::value == 1, ""); + static_assert(tuple_size::value == 3, ""); + static_assert(tuple_size>>::value == 1, ""); + + static_assert(tuple_size>::value == 0, ""); + static_assert(tuple_size>::value == 1, ""); + static_assert(tuple_size>::value == 1, ""); + static_assert(tuple_size::value == 3, ""); + static_assert(tuple_size>>::value == 1,""); } diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element.cc index dda293d93ec..09ba7a27b54 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element.cc @@ -1,3 +1,4 @@ +// { dg-do compile } // { dg-options "-std=gnu++11" } // // Copyright (C) 2011-2015 Free Software Foundation, Inc. @@ -29,9 +30,31 @@ test01() const size_t len = 3; typedef array array_type; - VERIFY( (is_same::type, int>::value == true) ); - VERIFY( (is_same::type, int>::value == true) ); - VERIFY( (is_same::type, int>::value == true) ); + + static_assert(is_same::type, int>::value, "" ); + static_assert(is_same::type, int>::value, "" ); + static_assert(is_same::type, int>::value, ""); + + static_assert(is_same::type, + const int>::value, ""); + static_assert(is_same::type, + const int>::value, ""); + static_assert(is_same::type, + const int>::value, ""); + + static_assert(is_same::type, + volatile int>::value, ""); + static_assert(is_same::type, + volatile int>::value, ""); + static_assert( (is_same::type, + volatile int>::value == true) ); + + static_assert(is_same::type, + const volatile int>::value, ""); + static_assert(is_same::type, + const volatile int>::value, ""); + static_assert(is_same::type, + const volatile int>::value, ""); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_cpp14.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_cpp14.cc new file mode 100644 index 00000000000..b885ea3e303 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_cpp14.cc @@ -0,0 +1,64 @@ +// { dg-do compile } +// { dg-options "-std=gnu++14" } +// +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + const size_t len = 3; + typedef array array_type; + + static_assert(is_same, int>::value, ""); + static_assert(is_same, int>::value, ""); + static_assert(is_same, int>::value, ""); + + static_assert(is_same, + const int>::value, ""); + static_assert(is_same, + const int>::value, ""); + static_assert(is_same, + const int>::value, ""); + + static_assert(is_same, + volatile int>::value, ""); + static_assert(is_same, + volatile int>::value, ""); + static_assert(is_same, + volatile int>::value, ""); + + static_assert(is_same, + const volatile int>::value, ""); + static_assert(is_same, + const volatile int>::value, ""); + static_assert(is_same, + const volatile int>::value, ""); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_size.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_size.cc index 59326857cc8..a821fdeb559 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_size.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_size.cc @@ -1,3 +1,4 @@ +// { dg-do compile } // { dg-options "-std=gnu++11" } // // Copyright (C) 2011-2015 Free Software Foundation, Inc. @@ -29,13 +30,19 @@ test01() { const size_t len = 5; typedef array array_type; - VERIFY( tuple_size::value == 5 ); + static_assert(tuple_size::value == 5, ""); + static_assert(tuple_size::value == 5, ""); + static_assert(tuple_size::value == 5, ""); + static_assert(tuple_size::value == 5, ""); } { const size_t len = 0; typedef array array_type; - VERIFY( tuple_size::value == 0 ); + static_assert(tuple_size::value == 0, ""); + static_assert(tuple_size::value == 0, ""); + static_assert(tuple_size::value == 0, ""); + static_assert(tuple_size::value == 0, ""); } }