From 373c726ec641e33ca640a51d6f4200318101f49d Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 6 Feb 2019 17:25:26 +0000 Subject: [PATCH] PR libstdc++/89102 fix common_type<> and common_type specializations This is a partial implementation of the revised std::common_type rules from P0435R1. PR libstdc++/89102 (partial) * include/std/type_traits (common_type<>): Define. (common_type): Derive from common_type. * testsuite/20_util/common_type/requirements/explicit_instantiation.cc: Test zero-length template argument list. * testsuite/20_util/common_type/requirements/sfinae_friendly_1.cc: Test additional single argument cases. * testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc: Adjust expected error. From-SVN: r268586 --- libstdc++-v3/ChangeLog | 12 ++++++++++++ libstdc++-v3/include/std/type_traits | 7 ++++++- .../requirements/explicit_instantiation.cc | 1 + .../common_type/requirements/sfinae_friendly_1.cc | 13 +++++++++++++ .../common_type/requirements/sfinae_friendly_2.cc | 2 +- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e08c08a0cf8..32061270c7a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,15 @@ +2019-02-06 Jonathan Wakely + + PR libstdc++/89102 (partial) + * include/std/type_traits (common_type<>): Define. + (common_type): Derive from common_type. + * testsuite/20_util/common_type/requirements/explicit_instantiation.cc: + Test zero-length template argument list. + * testsuite/20_util/common_type/requirements/sfinae_friendly_1.cc: + Test additional single argument cases. + * testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc: + Adjust expected error. + 2019-02-05 Jonathan Wakely PR libstdc++/89128 diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index f05a583cb04..bc2250d9dce 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2132,9 +2132,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __expanded_common_type_wrapper<__failure_type, _Args...> { typedef __failure_type type; }; + template<> + struct common_type<> + { }; + template struct common_type<_Tp> - { typedef typename decay<_Tp>::type type; }; + : common_type<_Tp, _Tp> + { }; template struct common_type<_Tp, _Up> diff --git a/libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc index 28535a80d64..dc57ab5ad8e 100644 --- a/libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc +++ b/libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc @@ -30,6 +30,7 @@ namespace std typedef void test_type5; typedef const void test_type6; + template struct common_type<>; template struct common_type; template struct common_type; template struct common_type; diff --git a/libstdc++-v3/testsuite/20_util/common_type/requirements/sfinae_friendly_1.cc b/libstdc++-v3/testsuite/20_util/common_type/requirements/sfinae_friendly_1.cc index 372c1a58378..9b94eb13434 100644 --- a/libstdc++-v3/testsuite/20_util/common_type/requirements/sfinae_friendly_1.cc +++ b/libstdc++-v3/testsuite/20_util/common_type/requirements/sfinae_friendly_1.cc @@ -159,7 +159,10 @@ namespace std { }; } +static_assert(is_type, int>(), ""); +static_assert(is_type, int>(), ""); static_assert(is_type, int>(), ""); +static_assert(is_type, int>(), ""); static_assert(is_type, ScEn>(), ""); static_assert(is_type, UnscEn>(), ""); static_assert(is_type, int>(), ""); @@ -180,6 +183,8 @@ static_assert(is_type, const volatile int*>(), ""); static_assert(is_type, const volatile void*>(), ""); +static_assert(is_type, void>(), ""); +static_assert(is_type, void>(), ""); static_assert(is_type, void>(), ""); static_assert(is_type, void>(), ""); static_assert(is_type, int>(), ""); @@ -316,6 +321,14 @@ static_assert(!has_type>(), ""); static_assert(!has_type, std::initializer_list>>(), ""); +// PR libstdc++/89102 +static_assert(!has_type>(), ""); +static_assert(!has_type>(), ""); +static_assert(!has_type>(), ""); +static_assert(!has_type>(), ""); +static_assert(!has_type>(), ""); +static_assert(!has_type>(), ""); + void test(int i) { auto local_lmd1 = [=](int, double) { return i + i; }; diff --git a/libstdc++-v3/testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc b/libstdc++-v3/testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc index 64c8ea9339e..8f6f4ecd4d8 100644 --- a/libstdc++-v3/testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc +++ b/libstdc++-v3/testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc @@ -25,7 +25,7 @@ template constexpr std::array::type, sizeof...(Args)> -make_array(Args&&... args) // { dg-error "invalid use" } +make_array(Args&&... args) // { dg-error "no type.*common_type<>" } { typedef typename std::common_type::type CT; return std::array{static_cast -- 2.30.2