mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-11 13:23:04 +00:00
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.
This commit is contained in:
@@ -250,7 +250,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. */
|
||||
@@ -465,24 +465,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;
|
||||
|
||||
Reference in New Issue
Block a user