c++/8277: g++ 3.2 is confused by operators and namespaces
mathias@valpo.de
mathias@valpo.de
Fri Oct 18 08:56:00 GMT 2002
>Number: 8277
>Category: c++
>Synopsis: g++ 3.2 is confused by operators and namespaces
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Fri Oct 18 08:56:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: mathias@valpo.de
>Release: unknown-1.0
>Organization:
>Environment:
kernel 2.4.19,
gcc 3.2 (Suse rpm package),
x86 (Athlon)
__GLIBCPP__ 20020814
>Description:
g++ seems to get confused by comparing stl-containers,
if the containers type is located in its own namespace:
g++ -c works, but g++ -c -DDOERROR gives the error msg
/usr/include/g++/bits/stl_algobase.h: In function `bool std::equal(_InputIter1,
_InputIter1, _InputIter2) [with _InputIter1 =
__gnu_cxx::__normal_iterator<const X::A*, std::vector<X::A,
std::allocator<X::A> > >, _InputIter2 = __gnu_cxx::__normal_iterator<const
X::A*, std::vector<X::A, std::allocator<X::A> > >]':
/usr/include/g++/bits/stl_vector.h:763: instantiated from `bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&) [with _Tp = X::A, _Alloc = std::allocator<X::A>]'
t.cpp:17: instantiated from here
/usr/include/g++/bits/stl_algobase.h:681: no match for `const X::A& == const
X::A&' operator
>How-To-Repeat:
#include <iostream>
#include <vector>
namespace X {
struct A {
std::vector<A> x ;
int y ;
A() : x(), y(0) {;}
};
}
bool operator== ( const X::A& a, const X::A& b )
{
#if DOERROR
return a.x == b.x ;
#else
return a.y == b.y ;
#endif
}
int main ()
{
X::A a ;
X::A b ;
const bool ret = a == b ;
std::cout << "bool: " << ret << std::endl ;
return 0 ;
}
>Fix:
Add the operator to the same namespace as the containers type:
namespace X {
bool operator== ( const X::A& a, const X::A& b )
{
#if DOERROR
return a.x == b.x ;
#else
return a.y == b.y ;
#endif
}
}
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list