public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50941] New: [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t
@ 2011-11-01 10:05 daniel.kruegler at googlemail dot com
  2011-11-01 10:25 ` [Bug c++/50941] " daniel.kruegler at googlemail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2011-11-01 10:05 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50941
           Summary: [C++0x] user-defined string literals provide incorrect
                    length for wchar_t, char16_t, and char32_t
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: daniel.kruegler@googlemail.com
                CC: jason@redhat.com


gcc 4.7.0 20111029 (experimental) in C++0x mode rejects the following code:

//---
typedef decltype(sizeof(0)) size_type;

constexpr size_type operator "" _len(const char*, size_type len)
{
  return len;
}

constexpr size_type operator "" _len(const wchar_t*, size_type len)
{
  return len;
}

constexpr size_type operator "" _len(const char16_t*, size_type len)
{
  return len;
}

constexpr size_type operator "" _len(const char32_t*, size_type len)
{
  return len;
}

static_assert(  ""_len == 0, "Ouch"); // OK
static_assert(u8""_len == 0, "Ouch"); // OK
static_assert( L""_len == 0, "Ouch"); // Error
static_assert( u""_len == 0, "Ouch"); // Error
static_assert( U""_len == 0, "Ouch"); // Error
//---

With 

"error: static assertion failed: "Ouch"" 

at the marked lines.

The code should be accepted.

It turns out that for wchar_t, char16_t, and char32_t string literals the
provided length is 1, not 0. But according to N3290 2.14.8 p5 and 2.14.5 p15
the provided length value should also be 0 in above examples. This problem also
occurs for non-empty strings: The length value is always too large by 1 for the
mentioned string types.


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

end of thread, other threads:[~2011-11-04 16:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-01 10:05 [Bug c++/50941] New: [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t daniel.kruegler at googlemail dot com
2011-11-01 10:25 ` [Bug c++/50941] " daniel.kruegler at googlemail dot com
2011-11-01 21:55 ` 3dw4rd at verizon dot net
2011-11-02  4:22 ` 3dw4rd at verizon dot net
2011-11-02  7:43 ` jakub at gcc dot gnu.org
2011-11-03  1:15 ` 3dw4rd at verizon dot net
2011-11-03  1:16 ` 3dw4rd at verizon dot net
2011-11-04 16:17 ` jason at gcc dot gnu.org
2011-11-04 16:27 ` jason at gcc dot gnu.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).