You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by "Martin Sebor (JIRA)" <ji...@apache.org> on 2006/06/28 19:55:29 UTC

[jira] Created: (STDCXX-214) std::char_traits::compare() broken for negative characters

std::char_traits<char>::compare() broken for negative characters
----------------------------------------------------------------

         Key: STDCXX-214
         URL: http://issues.apache.org/jira/browse/STDCXX-214
     Project: C++ Standard Library
        Type: Bug

  Components: 21. Strings  
    Versions: 4.1.2, 4.1.3    
 Environment: all
    Reporter: Martin Sebor


Moved from the Rogue Wave bug tracking database:

****Created By: sebor @ May 03, 2004 03:04:54 PM****
According to Table 37 in [lib.char.traits.require]:

X::compare(p,q,n) yields: 0 if for each i in [0,n), X::eq(p[i],q[i]) is true; else, a negative value if, for some j in [0,n), X::lt(p[j],q[j]) is true and for each i in [0,j) X::eq(p[i],q[i]) is true; else a positive value.

The following fails with gcc 3.4 on SunOS 5.7 because char_traits<char>::compare() uses memcmp() which, on this platform, compares characters as if they were unsigned.

$ cat t.cpp && ./t
/*   1 */ #include <cassert>
/*   2 */ #include <string>
/*   3 */ 
/*   4 */ int main ()
/*   5 */ {
/*   6 */     typedef std::char_traits<char> Traits;
/*   7 */ 
/*   8 */     const char s[] = "\0\377";
/*   9 */ 
/*  10 */     if (Traits::lt (s [0], s [1]))
/*  11 */         assert (Traits::compare (s + 0, s + 1, 1) < 0);
/*  12 */     else
/*  13 */         assert (Traits::compare (s + 0, s + 1, 1) > 0);
/*  14 */ }
/*  15 */ 
Assertion failed: Traits::compare (s + 0, s + 1, 1) > 0, file t.cpp, line 13
Abort (core dumped)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (STDCXX-214) [LWG #467] std::char_traits::compare() broken for negative characters

Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/STDCXX-214?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Martin Sebor updated STDCXX-214:
--------------------------------

    Summary: [LWG #467] std::char_traits<char>::compare() broken for negative characters  (was: std::char_traits<char>::compare() broken for negative characters)

This problem is the subject of Library Working Group issue 467:
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#467

> [LWG #467] std::char_traits<char>::compare() broken for negative characters
> ---------------------------------------------------------------------------
>
>                 Key: STDCXX-214
>                 URL: https://issues.apache.org/jira/browse/STDCXX-214
>             Project: C++ Standard Library
>          Issue Type: Bug
>          Components: 21. Strings
>    Affects Versions: 4.1.3, 4.1.2
>         Environment: all
>            Reporter: Martin Sebor
>         Assigned To: Martin Sebor
>
> Moved from the Rogue Wave bug tracking database:
> ****Created By: sebor @ May 03, 2004 03:04:54 PM****
> According to Table 37 in [lib.char.traits.require]:
> X::compare(p,q,n) yields: 0 if for each i in [0,n), X::eq(p[i],q[i]) is true; else, a negative value if, for some j in [0,n), X::lt(p[j],q[j]) is true and for each i in [0,j) X::eq(p[i],q[i]) is true; else a positive value.
> The following fails with gcc 3.4 on SunOS 5.7 because char_traits<char>::compare() uses memcmp() which, on this platform, compares characters as if they were unsigned.
> $ cat t.cpp && ./t
> /*   1 */ #include <cassert>
> /*   2 */ #include <string>
> /*   3 */ 
> /*   4 */ int main ()
> /*   5 */ {
> /*   6 */     typedef std::char_traits<char> Traits;
> /*   7 */ 
> /*   8 */     const char s[] = "\0\377";
> /*   9 */ 
> /*  10 */     if (Traits::lt (s [0], s [1]))
> /*  11 */         assert (Traits::compare (s + 0, s + 1, 1) < 0);
> /*  12 */     else
> /*  13 */         assert (Traits::compare (s + 0, s + 1, 1) > 0);
> /*  14 */ }
> /*  15 */ 
> Assertion failed: Traits::compare (s + 0, s + 1, 1) > 0, file t.cpp, line 13
> Abort (core dumped)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (STDCXX-214) [LWG #467] std::char_traits::compare() broken for negative characters

Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/STDCXX-214?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Martin Sebor resolved STDCXX-214.
---------------------------------

       Resolution: Fixed
    Fix Version/s: 4.2

Fixed. Need to add a test to the test suite.

> [LWG #467] std::char_traits<char>::compare() broken for negative characters
> ---------------------------------------------------------------------------
>
>                 Key: STDCXX-214
>                 URL: https://issues.apache.org/jira/browse/STDCXX-214
>             Project: C++ Standard Library
>          Issue Type: Bug
>          Components: 21. Strings
>    Affects Versions: 4.1.3, 4.1.2
>         Environment: all
>            Reporter: Martin Sebor
>         Assigned To: Martin Sebor
>             Fix For: 4.2
>
>
> Moved from the Rogue Wave bug tracking database:
> ****Created By: sebor @ May 03, 2004 03:04:54 PM****
> According to Table 37 in [lib.char.traits.require]:
> X::compare(p,q,n) yields: 0 if for each i in [0,n), X::eq(p[i],q[i]) is true; else, a negative value if, for some j in [0,n), X::lt(p[j],q[j]) is true and for each i in [0,j) X::eq(p[i],q[i]) is true; else a positive value.
> The following fails with gcc 3.4 on SunOS 5.7 because char_traits<char>::compare() uses memcmp() which, on this platform, compares characters as if they were unsigned.
> $ cat t.cpp && ./t
> /*   1 */ #include <cassert>
> /*   2 */ #include <string>
> /*   3 */ 
> /*   4 */ int main ()
> /*   5 */ {
> /*   6 */     typedef std::char_traits<char> Traits;
> /*   7 */ 
> /*   8 */     const char s[] = "\0\377";
> /*   9 */ 
> /*  10 */     if (Traits::lt (s [0], s [1]))
> /*  11 */         assert (Traits::compare (s + 0, s + 1, 1) < 0);
> /*  12 */     else
> /*  13 */         assert (Traits::compare (s + 0, s + 1, 1) > 0);
> /*  14 */ }
> /*  15 */ 
> Assertion failed: Traits::compare (s + 0, s + 1, 1) > 0, file t.cpp, line 13
> Abort (core dumped)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (STDCXX-214) std::char_traits::compare() broken for negative characters

Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/STDCXX-214?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Martin Sebor reassigned STDCXX-214:
-----------------------------------

    Assignee: Martin Sebor

> std::char_traits<char>::compare() broken for negative characters
> ----------------------------------------------------------------
>
>                 Key: STDCXX-214
>                 URL: https://issues.apache.org/jira/browse/STDCXX-214
>             Project: C++ Standard Library
>          Issue Type: Bug
>          Components: 21. Strings
>    Affects Versions: 4.1.3, 4.1.2
>         Environment: all
>            Reporter: Martin Sebor
>         Assigned To: Martin Sebor
>
> Moved from the Rogue Wave bug tracking database:
> ****Created By: sebor @ May 03, 2004 03:04:54 PM****
> According to Table 37 in [lib.char.traits.require]:
> X::compare(p,q,n) yields: 0 if for each i in [0,n), X::eq(p[i],q[i]) is true; else, a negative value if, for some j in [0,n), X::lt(p[j],q[j]) is true and for each i in [0,j) X::eq(p[i],q[i]) is true; else a positive value.
> The following fails with gcc 3.4 on SunOS 5.7 because char_traits<char>::compare() uses memcmp() which, on this platform, compares characters as if they were unsigned.
> $ cat t.cpp && ./t
> /*   1 */ #include <cassert>
> /*   2 */ #include <string>
> /*   3 */ 
> /*   4 */ int main ()
> /*   5 */ {
> /*   6 */     typedef std::char_traits<char> Traits;
> /*   7 */ 
> /*   8 */     const char s[] = "\0\377";
> /*   9 */ 
> /*  10 */     if (Traits::lt (s [0], s [1]))
> /*  11 */         assert (Traits::compare (s + 0, s + 1, 1) < 0);
> /*  12 */     else
> /*  13 */         assert (Traits::compare (s + 0, s + 1, 1) > 0);
> /*  14 */ }
> /*  15 */ 
> Assertion failed: Traits::compare (s + 0, s + 1, 1) > 0, file t.cpp, line 13
> Abort (core dumped)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.