* [C++11 Patch] PR 50941
@ 2011-11-03 12:51 Ed Smith-Rowland
2011-11-03 12:58 ` Paolo Carlini
0 siblings, 1 reply; 3+ messages in thread
From: Ed Smith-Rowland @ 2011-11-03 12:51 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 83 bytes --]
Greetings,
Here is a one liner and a test case.
Checked on x86_64-linux-gnu.
Ed
[-- Attachment #2: patch_50941 --]
[-- Type: text/plain, Size: 1992 bytes --]
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 ();
[-- Attachment #3: CL_50941 --]
[-- Type: text/plain, Size: 312 bytes --]
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [C++11 Patch] PR 50941
2011-11-03 12:51 [C++11 Patch] PR 50941 Ed Smith-Rowland
@ 2011-11-03 12:58 ` Paolo Carlini
2011-11-03 14:20 ` Ed Smith-Rowland
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Carlini @ 2011-11-03 12:58 UTC (permalink / raw)
To: Ed Smith-Rowland; +Cc: gcc-patches
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [C++11 Patch] PR 50941
2011-11-03 12:58 ` Paolo Carlini
@ 2011-11-03 14:20 ` Ed Smith-Rowland
0 siblings, 0 replies; 3+ messages in thread
From: Ed Smith-Rowland @ 2011-11-03 14:20 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 318 bytes --]
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
[-- Attachment #2: patch_50941 --]
[-- Type: text/plain, Size: 2557 bytes --]
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 ();
[-- Attachment #3: CL_50941 --]
[-- Type: text/plain, Size: 312 bytes --]
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-11-03 14:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-03 12:51 [C++11 Patch] PR 50941 Ed Smith-Rowland
2011-11-03 12:58 ` Paolo Carlini
2011-11-03 14:20 ` Ed Smith-Rowland
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).