diff mbox

[C++11] PR 50941

Message ID 4EB2A0D7.90409@verizon.net
State New
Headers show

Commit Message

Ed Smith-Rowland Nov. 3, 2011, 2:10 p.m. UTC
On 11/03/2011 08:50 AM, Paolo Carlini wrote:
> 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.
>
Arrrgh! ;-)

Here's a new patch.

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.
diff mbox

Patch

Index: libstdc++-v3/include/tr2/bool_set
===================================================================
--- libstdc++-v3/include/tr2/bool_set	(revision 180716)
+++ libstdc++-v3/include/tr2/bool_set	(working copy)
@@ -55,10 +55,10 @@ 
   public:
 
     ///  Default constructor.
-    bool_set() : _M_b(_S_false) { }
+    constexpr bool_set() : _M_b(_S_false) { }
 
     ///  Constructor from bool.
-    bool_set(bool __t) : _M_b(_Bool_set_val(__t)) { }
+    constexpr bool_set(bool __t) : _M_b(_Bool_set_val(__t)) { }
 
     ///
     // I'm not sure about this.
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 ();