From f7c511eebf14771c652131199e796ef95ffe6d50 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 6 May 2014 14:27:46 +0100 Subject: [PATCH] Backport libstdc++/60594 fix from mainline. PR libstdc++/60594 * include/std/functional (function::_Callable): Exclude own type from the callable checks. * testsuite/20_util/function/60594.cc: New. From-SVN: r210105 --- libstdc++-v3/ChangeLog | 10 ++++++ libstdc++-v3/include/std/functional | 11 ++++-- .../testsuite/20_util/function/60594.cc | 36 +++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/function/60594.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 77da71b8b9a7..c06f9c7a2dc7 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2014-05-06 Jonathan Wakely + + Backport from mainline + 2014-04-15 Jonathan Wakely + + PR libstdc++/60594 + * include/std/functional (function::_Callable): Exclude own type + from the callable checks. + * testsuite/20_util/function/60594.cc: New. + 2014-04-27 Jonathan Wakely PR libstdc++/60497 diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 64b6dae040bd..b31a33b0bef1 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -2181,8 +2181,15 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) using _Invoke = decltype(__callable_functor(std::declval<_Functor&>()) (std::declval<_ArgTypes>()...) ); + // Used so the return type convertibility checks aren't done when + // performing overload resolution for copy construction/assignment. + template + using _NotSelf = __not_>; + template - using _Callable = __check_func_return_type<_Invoke<_Functor>, _Res>; + using _Callable + = __and_<_NotSelf<_Functor>, + __check_func_return_type<_Invoke<_Functor>, _Res>>; template using _Requires = typename enable_if<_Cond::value, _Tp>::type; @@ -2323,7 +2330,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) * reference_wrapper, this function will not throw. */ template - _Requires<_Callable<_Functor>, function&> + _Requires<_Callable::type>, function&> operator=(_Functor&& __f) { function(std::forward<_Functor>(__f)).swap(*this); diff --git a/libstdc++-v3/testsuite/20_util/function/60594.cc b/libstdc++-v3/testsuite/20_util/function/60594.cc new file mode 100644 index 000000000000..be80b3f44d00 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/60594.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +// Copyright (C) 2011-2014 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 +// . + +// libstdc++/60594 + +#include +#include +struct bar; +using F = std::function; +// check for copy constructible and assignable while 'bar' is incomplete +constexpr int c = std::is_copy_constructible::value; +constexpr int a = std::is_copy_assignable::value; +struct bar { }; +bar func(); +void test() +{ + F g{ &func }; + g = func; +} -- 2.47.2