From patchwork Wed Oct 24 20:40:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v3] Another try at LWG 2141 Date: Wed, 24 Oct 2012 10:40:01 -0000 From: Paolo Carlini X-Patchwork-Id: 193949 Message-Id: <50885221.1030803@oracle.com> To: "gcc-patches@gcc.gnu.org" Cc: libstdc++ Hi, let's try again ;) In the light of discussion in Portland, which liked Marc's idea of using std::decay in the unary common_type too, the below seems good to go now, given that there are bad interactions with the front-end bug we have got. Tested x86_64-linux. Thanks, Paolo. /////////////////////// 2012-10-24 Daniel Krugler * include/std/type_traits (common_type): Implement LWG 2141. * testsuite/20_util/duration/requirements/sfinae_friendly_1.cc: Update. * testsuite/20_util/common_type/requirements/typedefs-1.cc: Likewise. * testsuite/20_util/common_type/requirements/sfinae_friendly_1.cc: Likewise. * testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc: Likewise. * testsuite/20_util/common_type/requirements/typedefs-2.cc: Likewise. Index: include/std/type_traits =================================================================== --- include/std/type_traits (revision 192762) +++ include/std/type_traits (working copy) @@ -1792,9 +1792,9 @@ struct __do_common_type_impl { template - static __success_type() - : std::declval<_Up>())> _S_test(int); + : std::declval<_Up>())>::type> _S_test(int); template static __failure_type _S_test(...); @@ -1835,7 +1835,7 @@ template struct common_type<_Tp> - { typedef _Tp type; }; + { typedef typename decay<_Tp>::type type; }; template struct common_type<_Tp, _Up> Index: testsuite/20_util/duration/requirements/sfinae_friendly_1.cc =================================================================== --- testsuite/20_util/duration/requirements/sfinae_friendly_1.cc (revision 192762) +++ testsuite/20_util/duration/requirements/sfinae_friendly_1.cc (working copy) @@ -21,9 +21,6 @@ #include #include -//TODO: Uncomment this once gcc bug 53000 has been resolved: -//#define HAS_53000_FIXED - // Helper types: struct has_type_impl { @@ -55,10 +52,8 @@ typedef std::chrono::duration ddn; typedef std::chrono::duration dim; -#ifdef HAS_53000_FIXED -static_assert(is_type, din&&>(), ""); -static_assert(is_type, din&&>(), ""); -#endif +static_assert(is_type, din>(), ""); +static_assert(is_type, din>(), ""); static_assert(is_type, ddn>(), ""); static_assert(is_type, ddn>(), ""); Index: testsuite/20_util/common_type/requirements/typedefs-1.cc =================================================================== --- testsuite/20_util/common_type/requirements/typedefs-1.cc (revision 192762) +++ testsuite/20_util/common_type/requirements/typedefs-1.cc (working copy) @@ -105,7 +105,7 @@ COMMON_TYPE_TEST_ALL_2(int, int, int, 1); COMMON_TYPE_TEST_ALL_2(int, double, double, 2); COMMON_TYPE_TEST_2(NO_CV, A, A, A, 3); - COMMON_TYPE_TEST_2(const, A, A, const A, 4); + COMMON_TYPE_TEST_2(const, A, A, A, 4); COMMON_TYPE_TEST_2(NO_CV, B, A, A, 5); } Index: testsuite/20_util/common_type/requirements/sfinae_friendly_1.cc =================================================================== --- testsuite/20_util/common_type/requirements/sfinae_friendly_1.cc (revision 192762) +++ testsuite/20_util/common_type/requirements/sfinae_friendly_1.cc (working copy) @@ -163,23 +163,19 @@ }; } -#ifdef HAS_53000_FIXED -static_assert(is_type, int&&>(), ""); -static_assert(is_type, ScEn&&>(), ""); -static_assert(is_type, UnscEn&&>(), ""); -#endif +static_assert(is_type, int>(), ""); +static_assert(is_type, ScEn>(), ""); +static_assert(is_type, UnscEn>(), ""); static_assert(is_type, int>(), ""); -#ifdef HAS_53000_FIXED -static_assert(is_type, int&&>(), ""); -static_assert(is_type, int&&>(), ""); -static_assert(is_type, int&&>(), ""); -static_assert(is_type, S&&>(), ""); -static_assert(is_type, const S&&>(), ""); +static_assert(is_type, int>(), ""); +static_assert(is_type, int>(), ""); +static_assert(is_type, int>(), ""); +static_assert(is_type, S>(), ""); +static_assert(is_type, S>(), ""); static_assert(is_type, - std::initializer_list>, std::initializer_list&&>(), ""); -static_assert(is_type, B&&>(), ""); -static_assert(is_type, B&&>(), ""); -#endif + std::initializer_list>, std::initializer_list>(), ""); +static_assert(is_type, B>(), ""); +static_assert(is_type, B>(), ""); static_assert(is_type, void*>(), ""); static_assert(is_type, void*>(), ""); static_assert(is_type, const volatile void*>(), ""); @@ -191,16 +187,12 @@ static_assert(is_type, void>(), ""); static_assert(is_type, void>(), ""); static_assert(is_type, int>(), ""); -static_assert(is_type, int&>(), ""); -#ifdef HAS_53000_FIXED -static_assert(is_type, int&&>(), ""); -static_assert(is_type, const int&&>(), ""); -#endif -static_assert(is_type, const U>(), ""); -static_assert(is_type, U&>(), ""); -#ifdef HAS_53000_FIXED -static_assert(is_type, U&&>(), ""); -#endif +static_assert(is_type, int>(), ""); +static_assert(is_type, int>(), ""); +static_assert(is_type, int>(), ""); +static_assert(is_type, U>(), ""); +static_assert(is_type, U>(), ""); +static_assert(is_type, U>(), ""); static_assert(is_type, int D::*>(), ""); static_assert(is_type, int D::*>(), ""); static_assert(is_type, @@ -209,34 +201,28 @@ int (D::*)()>(), ""); static_assert(is_type, int (D::*)() const>(), ""); -#ifdef HAS_53000_FIXED -static_assert(is_type, int(&&)[3]>(), ""); -#endif +static_assert(is_type, int*>(), ""); static_assert(is_type, const int*>(), ""); -static_assert(is_type, void(&)()>(), ""); -static_assert(is_type, void(&)()>(), ""); +static_assert(is_type, void(*)()>(), ""); +static_assert(is_type, void(*)()>(), ""); static_assert(is_type, - void(&)()>(), ""); + void(*)()>(), ""); static_assert(is_type, - void(&)()>(), ""); + void(*)()>(), ""); static_assert(is_type, - void(&)()>(), ""); + void(*)()>(), ""); static_assert(is_type, int>, int>(), ""); -#ifdef HAS_53000_FIXED static_assert(is_type, ImplicitTo>, - ImplicitTo&&>(), ""); -#endif + ImplicitTo>(), ""); static_assert(is_type, int, ImplicitTo>, int>(), ""); -#ifdef HAS_53000_FIXED static_assert(is_type, ExplicitTo>, - ExplicitTo&&>(), ""); + ExplicitTo>(), ""); static_assert(is_type, - decltype(lmd1)&&>(), ""); -#endif + decltype(lmd1)>(), ""); static_assert(is_type, - decltype(lmd1)&>(), ""); + decltype(lmd1)>(), ""); static_assert(is_type, void(*)(int, double)>(), ""); static_assert(is_type, void*>(), ""); @@ -251,9 +237,9 @@ int (B::*)() const>(), ""); static_assert(is_type, const int B::*>(), ""); -static_assert(is_type, Abstract&>(), ""); -static_assert(is_type, Ukn&>(), ""); -static_assert(is_type, B&>, B&>(), ""); +static_assert(is_type, Abstract>(), ""); +static_assert(is_type, Ukn>(), ""); +static_assert(is_type, B&>, B>(), ""); static_assert(is_type&, B&&>, B>(), ""); static_assert(is_type, const Abstract*>(), ""); @@ -262,12 +248,12 @@ #ifdef HAS_53000_FIXED static_assert(is_type, - Abstract&&>(), ""); + Abstract>(), ""); static_assert(is_type, const volatile Abstract&&>(), ""); -static_assert(is_type, Ukn&&>(), ""); + volatile Abstract&&>, Abstract>(), ""); +static_assert(is_type, Ukn>(), ""); static_assert(is_type, - const volatile Ukn&&>(), ""); + Ukn>(), ""); #endif static_assert(is_type, RX12>(), ""); @@ -337,14 +323,12 @@ auto local_lmd1 = [=](int, double) { return i + i; }; auto local_lmd2 = [=](int, double) { return i - i; }; -#ifdef HAS_53000_FIXED static_assert(is_type, decltype(local_lmd1)&&>(), ""); -#endif + decltype(local_lmd1)>, decltype(local_lmd1)>(), ""); static_assert(is_type, decltype(local_lmd1)>(), ""); static_assert(is_type, decltype(local_lmd1)&>(), ""); + decltype(local_lmd1)&>, decltype(local_lmd1)>(), ""); static_assert(!has_type>(), ""); Index: testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc =================================================================== --- testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc (revision 192762) +++ testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc (working copy) @@ -24,12 +24,11 @@ template constexpr -std::array::type>::type, +std::array::type, sizeof...(Args)> make_array(Args&&... args) // { dg-error "invalid use" } { - typedef typename std::decay::type>::type - CT; + typedef typename std::common_type::type CT; return std::array{static_cast (std::forward(args))...}; } @@ -39,10 +38,26 @@ constexpr auto a1 = make_array(0); constexpr auto a2 = make_array(0, 1.2); constexpr auto a3 = make_array(5, true, 3.1415f, 'c'); + + int i{}; + double d{1.2}; + float f{3.1415f}; + + auto b1 = make_array(i); + auto b2 = make_array(i, 1.2); + auto b3 = make_array(i, d); + auto b4 = make_array(0, d); + auto b5 = make_array(i, true, f, 'c'); static_assert(std::is_same>(), ""); static_assert(std::is_same>(), ""); static_assert(std::is_same>(), ""); + + static_assert(std::is_same>(), ""); + static_assert(std::is_same>(), ""); + static_assert(std::is_same>(), ""); + static_assert(std::is_same>(), ""); + static_assert(std::is_same>(), ""); } void test02() Index: testsuite/20_util/common_type/requirements/typedefs-2.cc =================================================================== --- testsuite/20_util/common_type/requirements/typedefs-2.cc (revision 192762) +++ testsuite/20_util/common_type/requirements/typedefs-2.cc (working copy) @@ -1,7 +1,7 @@ // { dg-options "-std=gnu++0x" } // 2009-11-12 Paolo Carlini // -// Copyright (C) 2009 Free Software Foundation, Inc. +// Copyright (C) 2009-2012 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 @@ -29,10 +29,9 @@ using std::is_same; VERIFY( (is_same::type, void>::value) ); - VERIFY( (is_same::type, const void>::value) ); - VERIFY( (is_same::type, volatile void>::value) ); - VERIFY( (is_same::type, - const volatile void>::value) ); + VERIFY( (is_same::type, void>::value) ); + VERIFY( (is_same::type, void>::value) ); + VERIFY( (is_same::type, void>::value) ); VERIFY( (is_same::type, void>::value) ); VERIFY( (is_same::type, void>::value) );