diff mbox

Use __invoke in std::function internals

Message ID 20160806121959.GC9156@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely Aug. 6, 2016, 12:19 p.m. UTC
On 05/08/16 10:00 +0100, Jonathan Wakely wrote:
>This fixes a bug in the _Callable SFINAE constraint of std::function,
>where it was using an rvalue _Func in the result_of expression, when
>the target is actually invoked as an lvalue.

I'm backporting this part to gcc-5 and gcc-6.

Tested x86_64-linux.
commit 07adfca77ea9e69addccacb38f3f6ddf90c6bced
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sat Aug 6 12:50:56 2016 +0100

    Use correct value category in std::function constraint
    
    	* include/std/functional (function::_Callable): Use lvalue in
    	result_of expression.
    	* testsuite/20_util/function/cons/refqual.cc: New test.
diff mbox

Patch

diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional
index 9799410..4f5b3c5 100644
--- a/libstdc++-v3/include/std/functional
+++ b/libstdc++-v3/include/std/functional
@@ -1847,7 +1847,7 @@  _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
       typedef _Res _Signature_type(_ArgTypes...);
 
       template<typename _Func,
-	       typename _Res2 = typename result_of<_Func(_ArgTypes...)>::type>
+	       typename _Res2 = typename result_of<_Func&(_ArgTypes...)>::type>
 	struct _Callable : __check_func_return_type<_Res2, _Res> { };
 
       // Used so the return type convertibility checks aren't done when
diff --git a/libstdc++-v3/testsuite/20_util/function/cons/refqual.cc b/libstdc++-v3/testsuite/20_util/function/cons/refqual.cc
new file mode 100644
index 0000000..d3744ee
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function/cons/refqual.cc
@@ -0,0 +1,31 @@ 
+// Copyright (C) 2016 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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+
+#include <functional>
+
+struct F {
+  void operator()() && { }
+  int operator()() & { return 0; }
+};
+
+int main() {
+  F f;
+  std::function<int()> ff{f};
+  return ff();
+}