The following program fails to compile (it compiles fine under 4.1.2) #include <iostream>
class MyClass { double x; public: MyClass(double X) : x(X) {} MyClass(int I) : x(I) {} friend bool operator&&(int i, const MyClass& Z); }; inline bool operator&&(int i, const MyClass& Z) { return int(Z.x) == i; } int main() { int k =3; MyClass X(3.1); std::cout << (k && X) << std::endl; } giving /usr/lib/gcc/i686-pc-linux-gnu/4.2.0-alpha20070131/include/g++-v4/ostream: In destructor 'std::basic_ostream<_CharT, _Traits>::sentry::~sentry() [with _CharT = char, _Traits = std::char_traits<char>]': /usr/lib/gcc/i686-pc-linux-gnu/4.2.0-alpha20070131/include/g++-v4/bits/ostream.tcc:70: instantiated from 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::_M_insert(_ValueT) [with _ValueT = bool, _CharT = char, _Traits = std::char_traits<char>]' /usr/lib/gcc/i686-pc-linux-gnu/4.2.0-alpha20070131/include/g++-v4/ostream:201: instantiated from 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>]' g++-4.2_bug.C:19: instantiated from here /usr/lib/gcc/i686-pc-linux-gnu/4.2.0-alpha20070131/include/g++-v4/ostream:455: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: /usr/lib/gcc/i686-pc-linux-gnu/4.2.0-alpha20070131/include/g++-v4/ostream:455: note: candidate 1: operator&&(bool, bool) <built-in> g++-4.2_bug.C:12: note: candidate 2: bool operator&&(int, const MyClass&) -- Summary: ostream ambiguous operator&& Product: gcc Version: 4.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jarausch at skynet dot be GCC host triplet: gcc-4.2.0-alpha20070131 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31031