This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

[v3] more explicit operator bool cleanup


Fixes for libstdc++/40273. Being a bit more proactive this time, added
tests to catch the last issue as well. 

tested x86_64/linux

-benjamin
2009-05-27  Benjamin Kosnik  <bkoz@redhat.com>

        PR libstdc++/40273
        * include/tr1_impl/functional: Add explicit cast.
        * testsuite/20_util/function/requirements/
        explicit_instantiation.cc: New.
        * testsuite/20_util/function/null_pointer_comparisons.cc: New.

Index: include/tr1_impl/functional
===================================================================
--- include/tr1_impl/functional	(revision 147925)
+++ include/tr1_impl/functional	(working copy)
@@ -1557,7 +1557,7 @@
 	template<typename _Signature>
 	  static bool
 	  _M_not_empty_function(const function<_Signature>& __f)
-	  { return __f; }
+          { return static_cast<bool>(__f); }
 
 	template<typename _Tp>
 	  static bool
@@ -2095,13 +2095,13 @@
   template<typename _Signature>
     inline bool
     operator==(const function<_Signature>& __f, _M_clear_type*)
-    { return !__f; }
+    { return !static_cast<bool>(__f); }
 
   /// @overload
   template<typename _Signature>
     inline bool
     operator==(_M_clear_type*, const function<_Signature>& __f)
-    { return !__f; }
+    { return !static_cast<bool>(__f); }
 
   /**
    *  @brief Compares a polymorphic function object wrapper against 0
@@ -2113,13 +2113,13 @@
   template<typename _Signature>
     inline bool
     operator!=(const function<_Signature>& __f, _M_clear_type*)
-    { return __f; }
+    { return static_cast<bool>(__f); }
 
   /// @overload
   template<typename _Signature>
     inline bool
     operator!=(_M_clear_type*, const function<_Signature>& __f)
-    { return __f; }
+    { return static_cast<bool>(__f); }
 
   // [3.7.2.8] specialized algorithms
 
Index: testsuite/20_util/function/requirements/explicit_instantiation.cc
===================================================================
--- testsuite/20_util/function/requirements/explicit_instantiation.cc	(revision 0)
+++ testsuite/20_util/function/requirements/explicit_instantiation.cc	(revision 0)
@@ -0,0 +1,26 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2009 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/>.
+
+#include <functional>
+
+namespace std
+{
+  template class function<void* ()>;
+}
Index: testsuite/20_util/function/null_pointer_comparisons.cc
===================================================================
--- testsuite/20_util/function/null_pointer_comparisons.cc	(revision 0)
+++ testsuite/20_util/function/null_pointer_comparisons.cc	(revision 0)
@@ -0,0 +1,44 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2009 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/>.
+
+#include <functional>
+
+// libstdc++/40273
+int main() 
+{
+  std::function<void* ()> f = 0;
+  if (f != 0) 
+    {
+    }
+
+  if (0 != f) 
+    {
+    }
+
+  if (f == 0) 
+    {
+    }
+
+  if (0 == f) 
+    {
+    }
+  return 0;
+}
+

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