diff mbox

[C++11] PR 50941

Message ID 4EB2818B.6010202@verizon.net
State New
Headers show

Commit Message

Ed Smith-Rowland Nov. 3, 2011, 11:56 a.m. UTC
Greetings,

Here is a one liner and a test case.
Checked on x86_64-linux-gnu.

Ed

2011-11-02  Ed Smith-Rowland  <3dw4rd@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.

Comments

Paolo Carlini Nov. 3, 2011, 12:50 p.m. UTC | #1
On 11/03/2011 12:56 PM, Ed Smith-Rowland wrote:
> +  len = TREE_STRING_LENGTH (value)
> +	/ TREE_INT_CST_LOW (TYPE_SIZE_UNIT ( TREE_TYPE(TREE_TYPE (value)))) - 1;
... with open brackets in random positions ;)

Paolo.
diff mbox

Patch

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 ();