Greetings, Here is a one liner and a test case. Checked on x86_64-linux-gnu.
Ed
Index: gcc/testsuite/g++.dg/cpp0x/udlit-string-length.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/udlit-string-length.C (revision 0) +++ gcc/testsuite/g++.dg/cpp0x/udlit-string-length.C (revision 0) @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// PR c++/50941 + +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"); +static_assert(u8""_len == 0, "Ouch"); +static_assert( L""_len == 0, "Ouch"); +static_assert( u""_len == 0, "Ouch"); +static_assert( U""_len == 0, "Ouch"); + +static_assert( "1"_len == 1, "Ouch"); +static_assert(u8"1"_len == 1, "Ouch"); +static_assert( L"1"_len == 1, "Ouch"); +static_assert( u"1"_len == 1, "Ouch"); +static_assert( U"1"_len == 1, "Ouch"); + +static_assert( "123"_len == 3, "Ouch"); +static_assert(u8"123"_len == 3, "Ouch"); +static_assert( L"123"_len == 3, "Ouch"); +static_assert( u"123"_len == 3, "Ouch"); +static_assert( U"123"_len == 3, "Ouch"); Index: gcc/cp/parser.c =================================================================== --- gcc/cp/parser.c (revision 180716) +++ gcc/cp/parser.c (working copy) @@ -3681,8 +3681,8 @@ suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal); name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id)); value = USERDEF_LITERAL_VALUE (literal); - len = TREE_STRING_LENGTH (value) - 1; - + len = TREE_STRING_LENGTH (value) + / TREE_INT_CST_LOW (TYPE_SIZE_UNIT ( TREE_TYPE(TREE_TYPE (value)))) - 1; /* Build up a call to the user-defined operator */ /* Lookup the name we got back from the id-expression. */ vec = make_tree_vector ();
2011-11-02 Ed Smith-Rowland <3dw...@verizon.net> DR c++/50941 gcc/testsuite/g++.dg/cpp0x/udlit-strint-length.C: New. DR c++/50941 gcc/cp/parser.c: (cp_parser_userdef_string_literal): To get the correct string length divide the tree string length by the character type size in bytes then subtract one.