Your message dated Sun, 22 May 2005 12:16:19 +0200
with message-id <[EMAIL PROTECTED]>
and subject line Bug#259196: libstdc++5: mixed signed/unsigned char comparison 
in std::char_traits<char>
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--------------------------------------
Received: (at submit) by bugs.debian.org; 13 Jul 2004 11:51:47 +0000
>From [EMAIL PROTECTED] Tue Jul 13 04:51:47 2004
Return-path: <[EMAIL PROTECTED]>
Received: from mail2.webmessenger.it (mail2a.webresidence.it) [193.70.193.55] 
        by spohr.debian.org with esmtp (Exim 3.35 1 (Debian))
        id 1BkLp5-000683-00; Tue, 13 Jul 2004 04:51:47 -0700
Received: from bohr.pisa.iol.it (193.76.233.84) by mail2a.webresidence.it 
(7.0.027-DD01)
        id 40F2821E000006E1; Tue, 13 Jul 2004 13:51:15 +0200
Received: from giuseppe by bohr.pisa.iol.it with local (Exim 4.32)
        id 1BkLoZ-0000oo-4e; Tue, 13 Jul 2004 13:51:15 +0200
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
From: giuseppe bonacci <[EMAIL PROTECTED]>
To: Debian Bug Tracking System <[EMAIL PROTECTED]>
Subject: libstdc++5: mixed signed/unsigned char comparison in 
std::char_traits<char>
X-Mailer: reportbug 2.62
Date: Tue, 13 Jul 2004 13:51:10 +0200
Message-Id: <[EMAIL PROTECTED]>
Sender: peppe <[EMAIL PROTECTED]>
Content-Transfer-Encoding: Quoted-Printable
Delivered-To: [EMAIL PROTECTED]
X-Spam-Checker-Version: SpamAssassin 2.60-bugs.debian.org_2004_03_25 
        (1.212-2003-09-23-exp) on spohr.debian.org
X-Spam-Status: No, hits=-8.0 required=4.0 tests=BAYES_00,HAS_PACKAGE 
        autolearn=no version=2.60-bugs.debian.org_2004_03_25
X-Spam-Level: 

Package: libstdc++5
Version: 1:3.3.4-2
Severity: minor

I report this as "minor" since I don't know if it's really a bug or
standard behaviour that I'm not understanding.

The following program (to be compiled with g++ 3.x)

#include <iostream>
#include <string>
#define BLURB(x) #x << "\t=3D=3D " << (x) << '\n'
int main()
{
    std::basic_string<char> s1, s2;
    s1 =3D 0xe0;
    s2 =3D 'a';
    std::cout << "s1 =3D=3D '" << s1 << "'\ns2 =3D=3D '" << s2 << "'\n";
    std::cout << BLURB( (s1 < s2) );
    std::cout << BLURB( (s1[0] < s2[0]) );
    std::cout << BLURB( std::char_traits<char>::lt(s1[0], s2[0]) );
    std::cout << BLURB( std::char_traits<char>::compare(s1.c_str(),
                s2.c_str(), 1) );
    std::cout << BLURB( s1.compare(s2) );
    return 0;
}

produces this output on my x86 linux pc:

s1 =3D=3D '=E0'
s2 =3D=3D 'a'
(s1 < s2)       =3D=3D 0
(s1[0] < s2[0]) =3D=3D 1
std::char_traits<char>::lt(s1[0], s2[0])        =3D=3D 1
std::char_traits<char>::compare(s1.c_str(), s2.c_str(), 1)      =3D=3D 1
s1.compare(s2)  =3D=3D 1

The above results are counter-intuitive, but agree with the
behaviour of C standard library (1999 standard):=20
- strcmp and memcmp treat their arguments as unsigned char*, so
  that strcmp(s1.c_str(), s2.c_str()) > 0 (meaning s1 > s2)
- on my platform char is signed, so s1[0] < s2[0] (because s1[0] < 0)

On the other hand, Stroustrup's TC++PL, section 20.2.1 "Character traits"
reports "The compare() function uses lt() and eq() to compare characters.=
",=20
so I'd expect
    std::char_traits<char>::lt(s1[0], s2[0])
and=20
    std::char_traits<char>::compare(s1.c_str(), s2.c_str(), 1)
to return consistent results, which they do not.  As a side effect,
s1.compare(s2) is not consistent with std::char_traits<char>::lt()
either.

As far as I can see, GNU libstdc++5 implementation of=20
std::char_traits<char>::compare() uses memcmp() instead of lt(), and so
inherits the unsigned char comparison, while std::char_traits<char>::lt()
plainly uses '<' to compare its arguments, keeping them signed.

It's quite likely that I am missing something in Stroustrup's book.
What does the standard mandate?

Best regards
giuseppe

-- System Information:
Debian Release: testing/unstable
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.4.26-1-686
Locale: LANG=3DC, LC_CTYPE=3DC

Versions of packages libstdc++5 depends on:
ii  gcc-3.3-base                1:3.3.4-2    The GNU Compiler Collection =
(base=20
ii  libc6                       2.3.2.ds1-13 GNU C Library: Shared librar=
ies an
ii  libgcc1                     1:3.3.4-2    GCC support library

-- no debconf information

---------------------------------------
Received: (at 259196-done) by bugs.debian.org; 22 May 2005 10:16:52 +0000
>From [EMAIL PROTECTED] Sun May 22 03:16:52 2005
Return-path: <[EMAIL PROTECTED]>
Received: from smtp06.web.de [217.72.192.224] 
        by spohr.debian.org with esmtp (Exim 3.35 1 (Debian))
        id 1DZnVs-0000KL-00; Sun, 22 May 2005 03:16:52 -0700
Received: from [213.23.67.203] (helo=juist)
        by smtp06.web.de with asmtp (TLSv1:DES-CBC3-SHA:168)
        (WEB.DE 4.105 #291)
        id 1DZnVN-0006yV-00
        for [EMAIL PROTECTED]; Sun, 22 May 2005 12:16:21 +0200
Received: from falk by juist with local (Exim 4.50)
        id 1DZnVL-0000z8-Ua
        for [EMAIL PROTECTED]; Sun, 22 May 2005 12:16:19 +0200
To: [EMAIL PROTECTED]
Subject: Bug#259196: libstdc++5: mixed signed/unsigned char comparison in
 std::char_traits<char>
From: Falk Hueffner <[EMAIL PROTECTED]>
X-Face: "iUeUu$b*W_"w?tV83Y3*r:`rh&dRv}$YnZ3,LVeCZSYVuf[Gpo*5%_=/\_!gc_,SS}[~xZ
 wY77I-M)xHIx:2f56g%/`SOw"Dx%4Xq0&f\Tj~>|QR|vGlU}TBYhiG(K:2<T^
Date: Sun, 22 May 2005 12:16:19 +0200
Message-ID: <[EMAIL PROTECTED]>
User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.5 (cilantro, linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Sender: [EMAIL PROTECTED]
X-Sender: [EMAIL PROTECTED]
Delivered-To: [EMAIL PROTECTED]
X-Spam-Checker-Version: SpamAssassin 2.60-bugs.debian.org_2005_01_02 
        (1.212-2003-09-23-exp) on spohr.debian.org
X-Spam-Status: No, hits=-4.0 required=4.0 tests=BAYES_00,HAS_BUG_NUMBER,
        RCVD_IN_DSBL autolearn=no version=2.60-bugs.debian.org_2005_01_02
X-Spam-Level: 

Hi,

acccording to http://gcc.gnu.org/PR15276, the behaviour has now been
codified by a DR as correct, so closing.

-- 
        Falk


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to