[Bug c++/33807] New: Incorrect ambiguous overload

2007-10-17 Thread bldantes at comcast dot net
The following code fails to compile with an overload ambiguity in gcc 4.2.1. It
successfully compiles in 3.4.4, 4.0.3 and 4.1.1. In the error message, note
also the bogus display of the signature for the first candidate:

note: candidates are: bool std::operator!=(const std::allocator<_CharT>&, const
std::allocator<_T2>&) [with _T1 = std::_List_node, _T2 =
std::_List_node]

bug.cc
--
#include 

template 
bool operator != (const T& x, const T& y) { return !(x == y); }

struct foo {};

void fnx() {
std::list l1, l2;
l1 = l2;
}

EOF


% g++ -c bug.cc
/usr/local/lib/gcc/ia64-hp-hpux11.31/4.2.1/../../../../include/c++/4.2.1/bits/stl_list.h:
In member function 'void std::list<_Tp,
_Alloc>::_M_check_equal_allocators(std::list<_Tp, _Alloc>&) [with _Tp = foo,
_Alloc = std::allocator]':
/usr/local/lib/gcc/ia64-hp-hpux11.31/4.2.1/../../../../include/c++/4.2.1/bits/stl_list.h:930:
  instantiated from 'void std::list<_Tp,
_Alloc>::splice(std::_List_iterator<_Tp>, std::list<_Tp, _Alloc>&) [with _Tp =
foo, _Alloc = std::allocator]'
/usr/local/lib/gcc/ia64-hp-hpux11.31/4.2.1/../../../../include/c++/4.2.1/bits/stl_list.h:833:
  instantiated from 'void std::list<_Tp,
_Alloc>::insert(std::_List_iterator<_Tp>, _InputIterator, _InputIterator) [with
_InputIterator = std::_List_const_iterator, _Tp = foo, _Alloc =
std::allocator]'
/usr/local/lib/gcc/ia64-hp-hpux11.31/4.2.1/../../../../include/c++/4.2.1/bits/list.tcc:135:
  instantiated from 'std::list<_Tp, _Alloc>& std::list<_Tp,
_Alloc>::operator=(const std::list<_Tp, _Alloc>&) [with _Tp = foo, _Alloc =
std::allocator]'
bug.cc:9:   instantiated from here
/usr/local/lib/gcc/ia64-hp-hpux11.31/4.2.1/../../../../include/c++/4.2.1/bits/stl_list.h:1179:
error: ambiguous overload for 'operator!=' in '((std::list >*)this)->std::list
>::.std::_List_base<_Tp, _Alloc>::_M_get_Node_allocator [with _Tp =
foo, _Alloc = std::allocator]() != ((std::list
>*)__x)->std::list >::.std::_List_base<_Tp,
_Alloc>::_M_get_Node_allocator [with _Tp = foo, _Alloc =
std::allocator]()'
/usr/local/lib/gcc/ia64-hp-hpux11.31/4.2.1/../../../../include/c++/4.2.1/bits/allocator.h:120:
note: candidates are: bool std::operator!=(const std::allocator<_CharT>&, const
std::allocator<_T2>&) [with _T1 = std::_List_node, _T2 =
std::_List_node]
/usr/local/lib/gcc/ia64-hp-hpux11.31/4.2.1/../../../../include/c++/4.2.1/ext/new_allocator.h:120:
note: bool __gnu_cxx::operator!=(const
__gnu_cxx::new_allocator<_Tp>&, const __gnu_cxx::new_allocator<_Tp>&) [with _Tp
= std::_List_node]
bug.cc:3: note: bool operator!=(const T&, const T&) [with T =
std::allocator >]

Compilation exited abnormally with code 1 at Wed Oct 17 22:53:00
%


-- 
   Summary: Incorrect ambiguous overload
       Product: gcc
   Version: 4.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bldantes at comcast dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33807



[Bug libstdc++/33807] Incorrect ambiguous overload

2007-10-18 Thread bldantes at comcast dot net


--- Comment #4 from bldantes at comcast dot net  2007-10-18 16:40 ---
Why does adding the new libstdc++ template function:

template
inline bool operator!=(const allocator<_Tp>&, const allocator<_Tp>&);

fix the conflict between my template function:

template 
bool operator != (const T& x, const T& y);

and the existing libstdc++ template function:

template
inline bool operator!=(const allocator<_T1>&, const allocator<_T2>&);

???

Before the addition of the new template function, it seems like the conflict in
the first place is just wrong. The compiler should pick the existing one in
libstdc++ over mine because it more closely matches the type, no?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33807