This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, C] PR18249
On Thu, 20 May 2010, Shujing Zhao wrote:
> + switch (desired)
> + {
> + case NLE_NULL:
> + break;
As I understand it, the previous code would have crashed in the cases that
now pass NLE_NULL - so those cases should never reach this part of the
function, and a call to gcc_unreachable () would be better than silently
continuing.
> + switch (desired)
> + {
> + case NLE_NULL:
> + break;
Likewise.
> @@ -19634,9 +19843,67 @@ cp_parser_require (cp_parser* parser,
> /* Output the MESSAGE -- unless we're parsing tentatively. */
> if (!cp_parser_simulate_error (parser))
> {
> - char *message = concat ("expected ", token_desc, NULL);
> - cp_parser_error (parser, message);
> - free (message);
> + char *buf;
> + switch (type)
> + {
> + case CPP_COLON:
> + if (strcmp (token_desc, "%<:%> or %<::%>") == 0)
> + cp_parser_error (parser, "expected %<:%> or %<::%>");
> + else
> + cp_parser_error (parser, "expected %<:%>");
> + break;
I don't like this approach of checking for magic strings in a description
parameter. Better to change that parameter to an enum. In the generic
cases
> + else
> + {
> + asprintf(&buf, G_("expected '%s'"), token_desc);
> + cp_parser_error (parser, buf);
> + free (buf);
> + case CPP_SEMICOLON:
[...]
> + case CPP_COMPL:
> + asprintf(&buf, G_("expected '%s'"), token_desc);
if you use an explicit cp_parser_error call for each case then you can
keep using %< and %> and so get consistent English quotes. (Actually, you
could get consistent quotes anyway by using %%< and %%> instead of '' in
the asprintf format string, as the result of asprintf gets passed through
the GCC format interpretation by cp_parser_error. But the double
interpretation isn't going to be obvious to translators, which itself is a
reason to avoid building up format strings with asprintf.)
--
Joseph S. Myers
joseph@codesourcery.com