This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] libstdc++/69293 Fix construction of std::function from null pointer-to-member


The wrong overload of _M_not_empty_function gets chosen and we treat a
null pointer-to-member as a valid target.

Tested powerpc64le-linux, comitted to trunk.


commit c0f055172fb4ceda0257a1a4ccd5f244609a0f37
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jan 18 11:25:43 2016 +0000

    Fix construction of std::function from null pointer-to-member
    
    	PR libstdc++/69293
    	* include/std/functional (_Function_base::_M_not_empty_function):
    	Change overloads for pointers to take arguments by value.
    	* testsuite/20_util/function/cons/57465.cc: Add tests for
    	pointer-to-member cases.

diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional
index 557156a..9799410 100644
--- a/libstdc++-v3/include/std/functional
+++ b/libstdc++-v3/include/std/functional
@@ -1633,13 +1633,13 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
 
 	template<typename _Tp>
 	  static bool
-	  _M_not_empty_function(_Tp* const& __fp)
-	  { return __fp; }
+	  _M_not_empty_function(_Tp* __fp)
+	  { return __fp != nullptr; }
 
 	template<typename _Class, typename _Tp>
 	  static bool
-	  _M_not_empty_function(_Tp _Class::* const& __mp)
-	  { return __mp; }
+	  _M_not_empty_function(_Tp _Class::* __mp)
+	  { return __mp != nullptr; }
 
 	template<typename _Tp>
 	  static bool
diff --git a/libstdc++-v3/testsuite/20_util/function/cons/57465.cc b/libstdc++-v3/testsuite/20_util/function/cons/57465.cc
index be2d132..7b13d4b 100644
--- a/libstdc++-v3/testsuite/20_util/function/cons/57465.cc
+++ b/libstdc++-v3/testsuite/20_util/function/cons/57465.cc
@@ -15,17 +15,33 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// libstdc++/57465
-
 // { dg-options "-std=gnu++11" }
 
 #include <functional>
 #include <testsuite_hooks.h>
 
-int main()
+void test01()
 {
   using F = void();
   F* f = nullptr;
   std::function<F> x(f);
-  VERIFY( !x );
+  VERIFY( !x ); // libstdc++/57465
+}
+
+void test02()
+{
+  struct X { };
+  int (X::*mf)() = nullptr;
+  std::function<int(X&)> f = mf;
+  VERIFY( !f ); // libstdc++/69243
+
+  int X::*mp = nullptr;
+  f = mp;
+  VERIFY( !f );
+}
+
+int main()
+{
+  test01();
+  test02();
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]