public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59873] New: The value of char32_t U'\u0000' and char16_t u'\u000' is 1, instead of 0.
@ 2014-01-18 22:02 wjl at icecavern dot net
  2014-01-18 22:05 ` [Bug c++/59873] " wjl at icecavern dot net
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: wjl at icecavern dot net @ 2014-01-18 22:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59873

            Bug ID: 59873
           Summary: The value of char32_t U'\u0000' and char16_t u'\u000'
                    is 1, instead of 0.
           Product: gcc
           Version: 4.8.3
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wjl at icecavern dot net

I found a major bug with char32_t and char16_t literals when trying to encode a
U+0000 (Null).

The following expressions have the numeric value 1, instead of the correct
value, 0. This makes it impossible to use code which has these literals.

The following typescript shows a program that demonstrates the problem, and
shows the behavior of g++ (incorrect) vs. clang++ (correct):

$ cat test.c++ 
#include <cstdint>
#include <iostream>

int main() {
    char32_t null = U'\u0000';
    std::cerr << "null (char32_t) = " << null << '\n';
    std::cerr << "null (uint32_t) = " << uint32_t(null) << '\n';

    char32_t soh = U'\u0001';
    std::cerr << "soh (char32_t) = " << soh << '\n';
    std::cerr << "soh (uint32_t) = " << uint32_t(soh) << '\n';

    std::cerr << "char32_t null == soh = " << (U'\u0000' == U'\u0001') << '\n';

    char16_t null16 = u'\u0000';
    std::cerr << "null (char16_t) = " << null16 << '\n';
    std::cerr << "null (uint16_t) = " << uint16_t(null16) << '\n';

    char16_t soh16 = u'\u0001';
    std::cerr << "soh (char16_t) = " << soh16 << '\n';
    std::cerr << "soh (uint16_t) = " << uint16_t(soh16) << '\n';

    std::cerr << "char16_t null == soh = " << (u'\u0000' == u'\u0001') << '\n';
}
$ g++ --version
g++ (Debian 4.8.2-10) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ -Wall -Wextra -std=c++11 test.c++
$ ./a.out
null (char32_t) = 1
null (uint32_t) = 1
soh (char32_t) = 1
soh (uint32_t) = 1
char32_t null == soh = 1
null (char16_t) = 1
null (uint16_t) = 1
soh (char16_t) = 1
soh (uint16_t) = 1
char16_t null == soh = 1
$ clang++ --version
Debian clang version 3.5-1 (trunk) (based on LLVM 3.5)
Target: x86_64-pc-linux-gnu
Thread model: posix
$ clang++ -Wall -Wextra -std=c++11 test.c++ 
$ ./a.out 
null (char32_t) = 0
null (uint32_t) = 0
soh (char32_t) = 1
soh (uint32_t) = 1
char32_t null == soh = 0
null (char16_t) = 0
null (uint16_t) = 0
soh (char16_t) = 1
soh (uint16_t) = 1
char16_t null == soh = 0


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

end of thread, other threads:[~2015-04-30 10:37 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-18 22:02 [Bug c++/59873] New: The value of char32_t U'\u0000' and char16_t u'\u000' is 1, instead of 0 wjl at icecavern dot net
2014-01-18 22:05 ` [Bug c++/59873] " wjl at icecavern dot net
2014-01-18 22:10 ` wjl at icecavern dot net
2014-01-18 23:19 ` wjl at icecavern dot net
2014-01-18 23:21 ` glisse at gcc dot gnu.org
2014-01-18 23:33 ` wjl at icecavern dot net
2014-01-18 23:40 ` schwab@linux-m68k.org
2014-01-18 23:47 ` wjl at icecavern dot net
2014-01-20  0:16 ` wjl at icecavern dot net
2014-01-20  0:19 ` wjl at icecavern dot net
2014-07-20 20:51 ` [Bug c++/59873] The value of char32_t U'\u0000' and char16_t u'\u0000' " richard-gccbugzilla at metafoo dot co.uk
2015-04-30 10:37 ` paolo.carlini at oracle dot com

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).