public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50941] New: [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t
@ 2011-11-01 10:05 daniel.kruegler at googlemail dot com
2011-11-01 10:25 ` [Bug c++/50941] " daniel.kruegler at googlemail dot com
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2011-11-01 10:05 UTC (permalink / raw)
To: gcc-bugs
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: unassigned@gcc.gnu.org
ReportedBy: daniel.kruegler@googlemail.com
CC: jason@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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/50941] [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t
2011-11-01 10:05 [Bug c++/50941] New: [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t daniel.kruegler at googlemail dot com
@ 2011-11-01 10:25 ` daniel.kruegler at googlemail dot com
2011-11-01 21:55 ` 3dw4rd at verizon dot net
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2011-11-01 10:25 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50941
--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2011-11-01 10:24:59 UTC ---
I need to make a correction in regard to the actually provided length values:
a) The following assertions incorrectly hold:
static_assert( L""_len == 1, "Ouch");
static_assert( u""_len == 1, "Ouch");
static_assert( U""_len == 3, "Ouch");
b) For non-empty strings other "value patterns" occur, e.g. these tests
static_assert(L"1"_len == 3, "Ouch");
static_assert(u"1"_len == 3, "Ouch");
static_assert(U"1"_len == 7, "Ouch");
evaluate to true, even though the length should be 1 in all these cases.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/50941] [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t
2011-11-01 10:05 [Bug c++/50941] New: [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t daniel.kruegler at googlemail dot com
2011-11-01 10:25 ` [Bug c++/50941] " daniel.kruegler at googlemail dot com
@ 2011-11-01 21:55 ` 3dw4rd at verizon dot net
2011-11-02 4:22 ` 3dw4rd at verizon dot net
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: 3dw4rd at verizon dot net @ 2011-11-01 21:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50941
--- Comment #2 from Ed Smith-Rowland <3dw4rd at verizon dot net> 2011-11-01 21:52:13 UTC ---
Divide by sizeof, then subtract 1.
Working on a patch.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/50941] [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t
2011-11-01 10:05 [Bug c++/50941] New: [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t daniel.kruegler at googlemail dot com
2011-11-01 10:25 ` [Bug c++/50941] " daniel.kruegler at googlemail dot com
2011-11-01 21:55 ` 3dw4rd at verizon dot net
@ 2011-11-02 4:22 ` 3dw4rd at verizon dot net
2011-11-02 7:43 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: 3dw4rd at verizon dot net @ 2011-11-02 4:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50941
--- Comment #3 from Ed Smith-Rowland <3dw4rd at verizon dot net> 2011-11-02 04:22:20 UTC ---
Created attachment 25685
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25685
Patch with testcase.
Patch. Testcase modified from initial report.
Thank you Daniel for the report.
Jason, should I rename the testcase after the bug number?
Ed
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/50941] [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t
2011-11-01 10:05 [Bug c++/50941] New: [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t daniel.kruegler at googlemail dot com
` (2 preceding siblings ...)
2011-11-02 4:22 ` 3dw4rd at verizon dot net
@ 2011-11-02 7:43 ` jakub at gcc dot gnu.org
2011-11-03 1:15 ` 3dw4rd at verizon dot net
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-11-02 7:43 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50941
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-11-02 07:43:06 UTC ---
Please watch your formatting:
UNIT ( TREE_TYPE( TREE_TYPE(value))))
should have been:
UNIT (TREE_TYPE (TREE_TYPE (value))))
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/50941] [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t
2011-11-01 10:05 [Bug c++/50941] New: [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t daniel.kruegler at googlemail dot com
` (3 preceding siblings ...)
2011-11-02 7:43 ` jakub at gcc dot gnu.org
@ 2011-11-03 1:15 ` 3dw4rd at verizon dot net
2011-11-03 1:16 ` 3dw4rd at verizon dot net
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: 3dw4rd at verizon dot net @ 2011-11-03 1:15 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50941
Ed Smith-Rowland <3dw4rd at verizon dot net> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #25685|0 |1
is obsolete| |
--- Comment #5 from Ed Smith-Rowland <3dw4rd at verizon dot net> 2011-11-03 01:14:44 UTC ---
Created attachment 25697
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25697
New patch with minor formatting and PR note in the testcase.
New patch.
Minor formatting.
Mention the PR in the testcase.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/50941] [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t
2011-11-01 10:05 [Bug c++/50941] New: [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t daniel.kruegler at googlemail dot com
` (4 preceding siblings ...)
2011-11-03 1:15 ` 3dw4rd at verizon dot net
@ 2011-11-03 1:16 ` 3dw4rd at verizon dot net
2011-11-04 16:17 ` jason at gcc dot gnu.org
2011-11-04 16:27 ` jason at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: 3dw4rd at verizon dot net @ 2011-11-03 1:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50941
--- Comment #6 from Ed Smith-Rowland <3dw4rd at verizon dot net> 2011-11-03 01:16:02 UTC ---
Ummm....
So do I post a patch and CL to gcc-patches if this is OK?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/50941] [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t
2011-11-01 10:05 [Bug c++/50941] New: [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t daniel.kruegler at googlemail dot com
` (5 preceding siblings ...)
2011-11-03 1:16 ` 3dw4rd at verizon dot net
@ 2011-11-04 16:17 ` jason at gcc dot gnu.org
2011-11-04 16:27 ` jason at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2011-11-04 16:17 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50941
--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> 2011-11-04 16:16:18 UTC ---
Author: jason
Date: Fri Nov 4 16:16:09 2011
New Revision: 180961
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=180961
Log:
PR c++/50941
* parser.c (cp_parser_userdef_string_literal): Fix string length.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/udlit-string-length.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/parser.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/50941] [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t
2011-11-01 10:05 [Bug c++/50941] New: [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t daniel.kruegler at googlemail dot com
` (6 preceding siblings ...)
2011-11-04 16:17 ` jason at gcc dot gnu.org
@ 2011-11-04 16:27 ` jason at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2011-11-04 16:27 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50941
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.7.0
--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> 2011-11-04 16:25:13 UTC ---
Fixed.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-11-04 16:27 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-01 10:05 [Bug c++/50941] New: [C++0x] user-defined string literals provide incorrect length for wchar_t, char16_t, and char32_t daniel.kruegler at googlemail dot com
2011-11-01 10:25 ` [Bug c++/50941] " daniel.kruegler at googlemail dot com
2011-11-01 21:55 ` 3dw4rd at verizon dot net
2011-11-02 4:22 ` 3dw4rd at verizon dot net
2011-11-02 7:43 ` jakub at gcc dot gnu.org
2011-11-03 1:15 ` 3dw4rd at verizon dot net
2011-11-03 1:16 ` 3dw4rd at verizon dot net
2011-11-04 16:17 ` jason at gcc dot gnu.org
2011-11-04 16:27 ` jason at gcc dot gnu.org
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).