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: unassig...@gcc.gnu.org ReportedBy: daniel.krueg...@googlemail.com CC: ja...@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.