This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/23871] New: iostream operator<<(int) uses || on integral operands
- From: "janis at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 Sep 2005 20:22:31 -0000
- Subject: [Bug libstdc++/23871] New: iostream operator<<(int) uses || on integral operands
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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].
--
Summary: iostream operator<<(int) uses || on integral operands
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: janis at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23871