Warn about character literals not of length one.

* NEWS (2.5): Document.
* src/scan-gram.l (INITIAL): Remove comment that we don't check
the length.
(SC_ESCAPED_CHARACTER): Warn if length is wrong.
* tests/input.at (Bad character literals): New test group.
(cherry picked from commit ac9b0e954b)
This commit is contained in:
Joel E. Denny
2009-07-24 10:29:07 -04:00
parent 13cdf208ed
commit 3208e3f4d9
4 changed files with 108 additions and 8 deletions

View File

@@ -260,7 +260,7 @@ splice (\\[ \f\t\v]*\n)*
complain_at (*loc, _("invalid identifier: %s"), quote (yytext));
}
/* Characters. We don't check there is only one. */
/* Characters. */
"'" STRING_GROW; token_start = loc->start; BEGIN SC_ESCAPED_CHARACTER;
/* Strings. */
@@ -493,24 +493,40 @@ splice (\\[ \f\t\v]*\n)*
<SC_ESCAPED_CHARACTER>
{
"'"|"\n" {
if (yytext[0] == '\n')
unexpected_newline (token_start, "'");
STRING_GROW;
STRING_FINISH;
loc->start = token_start;
val->character = last_string[1];
{
/* FIXME: Eventually, make these errors. */
size_t length = strlen (last_string);
if (strlen (last_string) < 3)
warn_at (*loc, _("empty character literal"));
else if (strlen (last_string) > 3)
warn_at (*loc, _("extra characters in character literal"));
}
if (yytext[0] == '\n')
unexpected_newline (token_start, "'");
STRING_FREE;
BEGIN INITIAL;
return CHAR;
}
<<EOF>> {
unexpected_eof (token_start, "'");
STRING_FINISH;
loc->start = token_start;
if (strlen (last_string) > 1)
val->character = last_string[1];
else
val->character = last_string[0];
{
size_t length = strlen (last_string);
/* FIXME: Eventually, make these errors. */
if (length < 2)
warn_at (*loc, _("empty character literal"));
else if (length > 2)
warn_at (*loc, _("extra characters in character literal"));
if (length > 1)
val->character = last_string[1];
else
val->character = last_string[0];
}
unexpected_eof (token_start, "'");
STRING_FREE;
BEGIN INITIAL;
return CHAR;