This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c++/2406: == operator does not work on vector<class x>
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/2406: == operator does not work on vector<class x>
- From: Joe Buck <jbuck at racerx dot synopsys dot com>
- Date: Tue, 27 Mar 2001 16:55:03 -0800 (PST)
>Number: 2406
>Category: c++
>Synopsis: == operator does not work on vector<class x>
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Mar 27 16:56:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Joe Buck
>Release: 3.0 20010327 (prerelease)
>Organization:
>Environment:
System: SunOS racerx 5.5.1 Generic_103640-34 sun4u sparc SUNW,Ultra-Enterprise
Architecture: sun4
host: sparc-sun-solaris2.5.1
build: sparc-sun-solaris2.5.1
target: sparc-sun-solaris2.5.1
configured with: ../gcc/configure --prefix=/u/jbuck/gcc-cvs --disable-nls
>Description:
The test case below fails to compile, evidently because <vector> does not
include the templated definition of operator!= .
We get
/u/jbuck/gcc-cvs/include/g++-v3/bits/stl_algobase.h: In function `bool
std::equal(_InputIter1, _InputIter1, _InputIter2) [with _InputIter1 =
std::__normal_iterator<const foo*, std::vector<foo, std::allocator<foo> > >,
_InputIter2 = std::__normal_iterator<const foo*, std::vector<foo,
std::allocator<foo> > >]':
/u/jbuck/gcc-cvs/include/g++-v3/bits/stl_vector.h:506: instantiated from `bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&) [with _Tp = foo, _Alloc = std::allocator<foo>]'
/remote/dtg103/jbuck/veq.cxx:12: instantiated from here
/u/jbuck/gcc-cvs/include/g++-v3/bits/stl_algobase.h:602: no match for `const
foo& != const foo&' operator
>How-To-Repeat:
-----------------------------------
#include <vector>
using std::vector;
struct foo {
int a;
};
bool operator==(const foo&, const foo&);
bool veq(const vector<foo>& a, const vector<foo>& b)
{
return a == b;
}
-----------------------------------
>Fix:
The user can add an explicit definition for
inline bool operator!=(const foo& a,const foo& b) { return !(a==b);}
but this isn't going to be acceptable in large code bases.
>Release-Note:
>Audit-Trail:
>Unformatted: