public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/23871] New: iostream operator<<(int) uses || on integral operands
@ 2005-09-13 20:22 janis at gcc dot gnu dot org
  2005-09-13 20:26 ` [Bug libstdc++/23871] [4.0 Regression] " pinskia at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: janis at gcc dot gnu dot org @ 2005-09-13 20:22 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2989 bytes --]

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-09-28  0:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-13 20:22 [Bug libstdc++/23871] New: iostream operator<<(int) uses || on integral operands janis at gcc dot gnu dot org
2005-09-13 20:26 ` [Bug libstdc++/23871] [4.0 Regression] " pinskia at gcc dot gnu dot org
2005-09-13 22:28 ` pcarlini at suse dot de
2005-09-16 20:18 ` cvs-commit at gcc dot gnu dot org
2005-09-27 16:08 ` mmitchel at gcc dot gnu dot org
2005-09-27 18:16 ` janis187 at us dot ibm dot com
2005-09-28  0:28 ` pinskia at gcc dot gnu dot org
2005-09-28  0:29 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).