This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix old-style quotations with parser->type_definition_forbidden_message
- From: Volker Reichelt <v dot reichelt at netcologne dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 29 Mar 2008 20:57:28 +0100 (CET)
- Subject: [PATCH] Fix old-style quotations with parser->type_definition_forbidden_message
The following patch fixes the last remaining issue with quotations in the
C++ parser: messages printed via parser->type_definition_forbidden_message.
The patch replaces the old-style quotations by the new locale-aware
quotations. But to make this work these quotations have to be interpreted.
Therefore we cannot print the message in cp_parser_check_type_definition
with "%s", but have to print the string directly.
Btw, the comment
/* Use `%s' to print the string in case there are any escape
characters in the message. */
is moot, because the only escape characters appearing are the quotes
which we want to interpret.
While fixing the quotation of FORMAT in cp_parser_sizeof_operand,
I replaced the cumbersome construction of the message TMP by a simple
CONCAT.
Bootstrapped and regtested on i686-pc-linux-gnu.
Ok for mainline?
Regards,
Volker
:ADDPATCH C++:
2008-03-29 Volker Reichelt <v.reichelt@netcologne.de>
* parser.c (cp_parser_check_type_definition): Print error string
directly rather than using "%s".
(cp_parser_postfix_expression): Fix quotation.
(cp_parser_decltype): Likewise.
(cp_parser_sizeof_operand): Fix quotation. Simplify.
========================================================================
--- gcc/cp/parser.c 2008-03-27 19:28:33 +0100
+++ gcc/cp/parser.c 2008-03-29 04:03:08 +0100
@@ -2183,9 +2183,9 @@ cp_parser_check_type_definition (cp_pars
/* If types are forbidden here, issue a message. */
if (parser->type_definition_forbidden_message)
{
- /* Use `%s' to print the string in case there are any escape
- characters in the message. */
- error ("%s", parser->type_definition_forbidden_message);
+ /* Don't use `%s' to print the string, because quotations (`%<', `%>')
+ in the message need to be interpreted. */
+ error (parser->type_definition_forbidden_message);
return false;
}
return true;
@@ -4367,7 +4367,7 @@ cp_parser_postfix_expression (cp_parser
/* Types cannot be defined in a `typeid' expression. */
saved_message = parser->type_definition_forbidden_message;
parser->type_definition_forbidden_message
- = "types may not be defined in a `typeid\' expression";
+ = "types may not be defined in a %<typeid%> expression";
/* We can't be sure yet whether we're looking at a type-id or an
expression. */
cp_parser_parse_tentatively (parser);
@@ -8510,7 +8510,7 @@ cp_parser_decltype (cp_parser *parser)
/* And create the new one. */
parser->type_definition_forbidden_message
- = "types may not be defined in `decltype' expressions";
+ = "types may not be defined in %<decltype%> expressions";
/* The restrictions on constant-expressions do not apply inside
decltype expressions. */
@@ -17571,7 +17571,6 @@ cp_parser_late_parsing_default_args (cp_
static tree
cp_parser_sizeof_operand (cp_parser* parser, enum rid keyword)
{
- static const char *format;
tree expr = NULL_TREE;
const char *saved_message;
char *tmp;
@@ -17579,19 +17578,14 @@ cp_parser_sizeof_operand (cp_parser* par
bool saved_non_integral_constant_expression_p;
bool pack_expansion_p = false;
- /* Initialize FORMAT the first time we get here. */
- if (!format)
- format = "types may not be defined in '%s' expressions";
-
/* Types cannot be defined in a `sizeof' expression. Save away the
old message. */
saved_message = parser->type_definition_forbidden_message;
/* And create the new one. */
- parser->type_definition_forbidden_message = tmp
- = XNEWVEC (char, strlen (format)
- + strlen (IDENTIFIER_POINTER (ridpointers[keyword]))
- + 1 /* `\0' */);
- sprintf (tmp, format, IDENTIFIER_POINTER (ridpointers[keyword]));
+ tmp = concat ("types may not be defined in %<",
+ IDENTIFIER_POINTER (ridpointers[keyword]),
+ "%> expressions", NULL);
+ parser->type_definition_forbidden_message = tmp;
/* The restrictions on constant-expressions do not apply inside
sizeof expressions. */
========================================================================