[C++ Patch] PR 57880
Paolo Carlini
paolo.carlini@oracle.com
Thu Jul 25 08:39:00 GMT 2013
On 07/25/2013 03:35 AM, Jason Merrill wrote:
> You need to have tests for the other string prefixes, since you're
> changing the code for them.
Oh yes, something like this?
(believe me, I had it, but then the last minute I simplified the
testcase because the last lines didn't seem to exercise any additional
code path in the new code. But I agree it may be useful if we do change
the code)
Thanks,
Paolo.
//////////////////
-------------- next part --------------
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 201233)
+++ cp/parser.c (working copy)
@@ -12261,7 +12261,6 @@ cp_parser_operator (cp_parser* parser)
tree id = NULL_TREE;
cp_token *token;
bool bad_encoding_prefix = false;
- int string_len = 2;
/* Peek at the next token. */
token = cp_lexer_peek_token (parser->lexer);
@@ -12462,20 +12461,22 @@ cp_parser_operator (cp_parser* parser)
return ansi_opname (ARRAY_REF);
case CPP_WSTRING:
- string_len = 3;
case CPP_STRING16:
case CPP_STRING32:
- string_len = 5;
case CPP_UTF8STRING:
- string_len = 4;
- bad_encoding_prefix = true;
+ bad_encoding_prefix = true;
+ /* Fall through. */
+
case CPP_STRING:
if (cxx_dialect == cxx98)
maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
if (bad_encoding_prefix)
- error ("invalid encoding prefix in literal operator");
- if (TREE_STRING_LENGTH (token->u.value) > string_len)
{
+ error ("invalid encoding prefix in literal operator");
+ return error_mark_node;
+ }
+ if (TREE_STRING_LENGTH (token->u.value) > 2)
+ {
error ("expected empty string after %<operator%> keyword");
return error_mark_node;
}
@@ -12505,21 +12506,23 @@ cp_parser_operator (cp_parser* parser)
}
case CPP_WSTRING_USERDEF:
- string_len = 3;
case CPP_STRING16_USERDEF:
case CPP_STRING32_USERDEF:
- string_len = 5;
case CPP_UTF8STRING_USERDEF:
- string_len = 4;
bad_encoding_prefix = true;
+ /* Fall through. */
+
case CPP_STRING_USERDEF:
if (cxx_dialect == cxx98)
maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
if (bad_encoding_prefix)
- error ("invalid encoding prefix in literal operator");
+ {
+ error ("invalid encoding prefix in literal operator");
+ return error_mark_node;
+ }
{
tree string_tree = USERDEF_LITERAL_VALUE (token->u.value);
- if (TREE_STRING_LENGTH (string_tree) > string_len)
+ if (TREE_STRING_LENGTH (string_tree) > 2)
{
error ("expected empty string after %<operator%> keyword");
return error_mark_node;
Index: testsuite/g++.dg/cpp1y/udlit-empty-string-neg.C
===================================================================
--- testsuite/g++.dg/cpp1y/udlit-empty-string-neg.C (revision 0)
+++ testsuite/g++.dg/cpp1y/udlit-empty-string-neg.C (working copy)
@@ -0,0 +1,21 @@
+// { dg-options -std=c++1y }
+
+int
+operator "*"_s(unsigned long long) // { dg-error "expected empty string after 'operator'" }
+{ return 0; }
+
+int
+operator L"*"_Ls(unsigned long long) // { dg-error "invalid encoding prefix in literal operator" }
+{ return 0; }
+
+int
+operator u"*"_s16(unsigned long long) // { dg-error "invalid encoding prefix in literal operator" }
+{ return 0; }
+
+int
+operator U"*"_s32(unsigned long long) // { dg-error "invalid encoding prefix in literal operator" }
+{ return 0; }
+
+int
+operator u8"*"_u8s(unsigned long long) // { dg-error "invalid encoding prefix in literal operator" }
+{ return 0; }
More information about the Gcc-patches
mailing list