This testcase from an IBM internal user: #include <iostream> class mytest { public: mytest (int); unsigned char operator|| (const mytest&) const; friend unsigned char operator|| (const int&, const mytest&); }; inline unsigned char operator|| (const int& lhs, const mytest& rhs) { std::cout << 1 << std::endl; return (mytest)lhs || rhs; } fails with FSF 4.0 releases and the current 4.0 branch with: elm3b11% /opt/gcc-nightly/4.0/bin/g++ -c bug.cc /home/gcc-nightly/4.0-20050913/bin/../lib/gcc/powerpc64-linux/4.0.2/../../../../include/c++/4.0.2/ostream: In member function ‘std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>]’: bug.cc:10: instantiated from here /home/gcc-nightly/4.0-20050913/bin/../lib/gcc/powerpc64-linux/4.0.2/../../../../include/c++/4.0.2/ostream:194: 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: /home/gcc-nightly/4.0-20050913/bin/../lib/gcc/powerpc64-linux/4.0.2/../../../../include/c++/4.0.2/ostream:194: note: candidate 1: operator||(bool, bool) <built-in> bug.cc:8: note: candidate 2: unsigned char operator||(const int&, const mytest&) This is due to code for operator<<(int) in std_ostream.h that uses || on integral (not bool) operands, leading to the ambiguity between the built-in || operator and one defined in the testcase. It is a regression because versions earlier than 4.0 failed to report the error. The testcase passes on mainline starting with this patch from Paolo Carlini: http://gcc.gnu.org/ml/gcc-cvs/2005-07/msg00424.html http://gcc.gnu.org/ml/gcc-patches/2005-07/msg00726.html I'm currently testing this part of that patch with the 4.0 branch: * include/std/std_ostream.h (operator<<(short), operator<<(int)): Adjust logic, as per the letter of the resolution of DR117 [WP].
Confirmed, a regression from 3.4.0. Just a note, 4.0 branch is frozen right now.
Yes, for 4.0.3 backporting only those bits would make sense. Thanks Janis for testing.
Subject: Bug 23871 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: janis@gcc.gnu.org 2005-09-16 20:18:11 Modified files: libstdc++-v3 : ChangeLog libstdc++-v3/include/std: std_ostream.h libstdc++-v3/include/bits: ostream.tcc Added files: libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char: 7.cc 23871.cc libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t: 7.cc Log message: PR libstdc++/23871 Backport: 2005-07-11 Paolo Carlini <pcarlini@suse.de> * include/std/std_ostream.h (operator<<(short), operator<<(int)): Adjust logic, as per the letter of the resolution of DR117 [WP]. * testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc: New. * testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc: New. * include/bits/ostream.tcc (operator<<(long), operator<<(long long)): Adjust logic. * testsuite/27_io/basic_ostream/inserters_arithmetic/char/23871.cc: New. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.2917.2.82&r2=1.2917.2.83 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/std/std_ostream.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.16&r2=1.16.12.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/ostream.tcc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.54&r2=1.54.12.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.2.4.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/23871.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.2.4.1
This is fixed in 4.0.2. I forgot and checked it into the branch before RC2; Paolo said it was safe and to leave it in unless Mark said to yank it out. I've messed up my Bugzilla settings and can't change the PR to "fixed".
Fixed for 4.0.2 as requested by Janis.