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]

Re: [libstdc++ patch] Fix to std::equal and bug c++/2406


Joe Buck <jbuck@racerx.synopsys.com> writes:

| See discussion on libstdc++ list.  This is to fix c++/2406.
| Papers not on file, but according to RMS this doesn't matter for a one liner.
| 
| 2001-04-03  Joe Buck  <jbuck@welsh-buck.org>
| 
| 	* stl_algobase.h (std::equal): avoid use of possibly-undefined
| 	operator != (one line patch).


Joe, this is applied on branch as attached.

-- Gaby

  2001-04-06  Gabriel Dos Reis  <gdr@codesourcery.com>
  
	* testsuite/25_algorithms/equal.cc: New test.

  2001-04-06  Joe Buck  <jbuck@welsh-buck.org>

        * stl_algobase.h (std::equal): avoid use of possibly-undefined
        operator != (one line patch).

Index: include/bits/stl_algobase.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_algobase.h,v
retrieving revision 1.3
diff -p -r1.3 stl_algobase.h
*** stl_algobase.h	2001/01/25 15:35:10	1.3
--- stl_algobase.h	2001/04/06 21:35:32
*************** inline bool equal(_InputIter1 __first1, 
*** 599,605 ****
    __STL_REQUIRES(typename iterator_traits<_InputIter2>::value_type,
                   _EqualityComparable);
    for ( ; __first1 != __last1; ++__first1, ++__first2)
!     if (*__first1 != *__first2)
        return false;
    return true;
  }
--- 599,605 ----
    __STL_REQUIRES(typename iterator_traits<_InputIter2>::value_type,
                   _EqualityComparable);
    for ( ; __first1 != __last1; ++__first1, ++__first2)
!     if (!(*__first1 == *__first2))
        return false;
    return true;
  }
Index: testsuite/25_algorithms/equal.cc
===================================================================
RCS file: equal.cc
diff -N equal.cc
*** /dev/null	Tue May  5 13:32:27 1998
--- equal.cc	Fri Apr  6 14:35:32 2001
***************
*** 0 ****
--- 1,41 ----
+ // 2001-04-06 gdr
+ 
+ // Copyright (C) 2000 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 2, 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 COPYING.  If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ #include <vector>
+ #include <algorithm>
+ 
+ //
+ // 25.1.8 Make sure std::equal doesn't make any extra assumption
+ //        about operator== and operator!=
+ //
+ 
+ struct X { };
+ 
+ bool operator==(X, X) { return true; }
+ 
+ // Not implemented on purpose.  { dg-do link }
+ bool operator!=(X, X);
+ 
+ int main()
+ {
+   std::vector<X> v, w;
+ 
+   return !std::equal(v.begin(), v.end(), w.begin());
+ }


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