tests: be strict about types

* tests/actions.at, tests/c++.at, tests/cxx-type.at,
* tests/glr-regression.at, tests/local.at, tests/torture.at,
* tests/types.at:
Pay stricter attention to types to avoid warnings.
This commit is contained in:
Akim Demaille
2018-10-22 11:15:02 +02:00
parent 0021bc3e28
commit b4b8666e4a
7 changed files with 25 additions and 28 deletions

View File

@@ -691,13 +691,13 @@ const char *source = YY_NULLPTR;
static static
]AT_YYLEX_PROTOTYPE[ ]AT_YYLEX_PROTOTYPE[
{ {
static unsigned counter = 0; static int counter = 0;
unsigned c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++; int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++;
/* As in BASIC, line numbers go from 10 to 10. */ /* As in BASIC, line numbers go from 10 to 10. */
]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = 10 * c; ]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = ]AT_CXX_IF([(unsigned)], [(int)])[(10 * c);
]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9; ]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9;
assert (c <= strlen (source)); assert (c <= (int) strlen (source));
if (source[c]) if (source[c])
fprintf (stderr, "sending: '%c'", source[c]); fprintf (stderr, "sending: '%c'", source[c]);
else else
@@ -1684,7 +1684,7 @@ AT_DATA_GRAMMAR([[input.y]],
%initial-action %initial-action
{ {
$<ival>$ = 42; $<ival>$ = 42;
$<fval>$ = 4.2; $<fval>$ = 4.2f;
} }
%% %%
@@ -1699,7 +1699,7 @@ float: UNTYPED INT
yy::parser::token::INT, yy::parser::token::INT,
EOF}]], EOF}]],
[[{UNTYPED, INT, EOF}]]), [[{UNTYPED, INT, EOF}]]),
[AT_VAL.ival = toknum * 10; AT_VAL.fval = toknum / 10.0;])[ [AT_VAL.ival = (int) toknum * 10; AT_VAL.fval = (float) toknum / 10.0f;])[
]AT_MAIN_DEFINE[ ]AT_MAIN_DEFINE[
]]) ]])
@@ -1816,7 +1816,7 @@ exp:
%% %%
]AT_YYERROR_DEFINE[ ]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["bcd"], [*lvalp = (toknum + 1) * 10])[ ]AT_YYLEX_DEFINE(["bcd"], [*lvalp = (int) ((toknum + 1) * 10)])[
]AT_MAIN_DEFINE[ ]AT_MAIN_DEFINE[
]]) ]])
AT_BISON_OPTION_POPDEFS AT_BISON_OPTION_POPDEFS

View File

@@ -1181,12 +1181,12 @@ yylex (yy::parser::semantic_type *lvalp)
// 'R': call YYERROR in the action // 'R': call YYERROR in the action
// 's': reduction throws. // 's': reduction throws.
// 'T': call YYABORT in the action // 'T': call YYABORT in the action
switch (int res = *input++) switch (char res = *input++)
{ {
case 'l': case 'l':
throw std::runtime_error ("yylex"); throw std::runtime_error ("yylex");
default: default:
lvalp->]AT_VARIANT_IF([build (Object (res))], lvalp->]AT_VARIANT_IF([build<Object> (res)],
[obj = new Object (res)])[; [obj = new Object (res)])[;
// Fall through. // Fall through.
case 0: case 0:

View File

@@ -137,9 +137,6 @@ main (int argc, char **argv)
]AT_YYLEX_PROTOTYPE[ ]AT_YYLEX_PROTOTYPE[
{ {
char buffer[256];
int c;
unsigned i;
static int lineNum = 1; static int lineNum = 1;
static int colNum = 0; static int colNum = 0;
@@ -152,6 +149,7 @@ main (int argc, char **argv)
while (1) while (1)
{ {
int c;
assert (!feof (stdin)); assert (!feof (stdin));
c = getchar (); c = getchar ();
switch (c) switch (c)
@@ -175,11 +173,12 @@ main (int argc, char **argv)
yylloc.first_column = colNum;]])[ yylloc.first_column = colNum;]])[
if (isalpha (c)) if (isalpha (c))
{ {
i = 0; char buffer[256];
unsigned i = 0;
do do
{ {
buffer[i++] = c; buffer[i++] = (char) c;
colNum += 1; colNum += 1;
assert (i != sizeof buffer - 1); assert (i != sizeof buffer - 1);
c = getchar (); c = getchar ();

View File

@@ -1000,8 +1000,7 @@ static int
merge (YYSTYPE s1, YYSTYPE s2) merge (YYSTYPE s1, YYSTYPE s2)
{ {
/* Not invoked. */ /* Not invoked. */
char dummy = s1.dummy + s2.dummy; return s1.dummy + s2.dummy;
return dummy;
} }
]AT_YYERROR_DEFINE[ ]AT_YYERROR_DEFINE[
@@ -1119,7 +1118,7 @@ change_lookahead:
]AT_YYERROR_DEFINE[ ]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["ab"], ]AT_YYLEX_DEFINE(["ab"],
[yylval.value = res + 'A' - 'a'])[ [yylval.value = (char) (res + 'A' - 'a')])[
static void static void
print_lookahead (char const *reduction) print_lookahead (char const *reduction)
@@ -1319,11 +1318,11 @@ static int
yylex (void) yylex (void)
{ {
static char const input[] = "abcdddd"; static char const input[] = "abcdddd";
static size_t toknum; static int toknum = 0;
assert (toknum < sizeof input); assert (toknum < (int) sizeof input);
yylloc.first_line = yylloc.last_line = 1; yylloc.first_line = yylloc.last_line = 1;
yylloc.first_column = yylloc.last_column = toknum + 1; yylloc.first_column = yylloc.last_column = toknum + 1;
yylval.value = input[toknum] + 'A' - 'a'; yylval.value = (char) (input[toknum] + 'A' - 'a');
return input[toknum++]; return input[toknum++];
} }
@@ -1350,8 +1349,7 @@ print_lookahead (char const *reduction)
static char static char
merge (union YYSTYPE s1, union YYSTYPE s2) merge (union YYSTYPE s1, union YYSTYPE s2)
{ {
char dummy = s1.value + s2.value; return (char) (s1.value + s2.value);
return dummy;
} }
int int
@@ -1578,8 +1576,8 @@ static int
yylex (YYSTYPE *lvalp, YYLTYPE *llocp) yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
{ {
static char const input[] = "ab"; static char const input[] = "ab";
static size_t toknum; static int toknum = 0;
assert (toknum < sizeof input); assert (toknum < (int) sizeof input);
lvalp->dummy = 0; lvalp->dummy = 0;
llocp->first_line = llocp->last_line = 2; llocp->first_line = llocp->last_line = 2;
llocp->first_column = toknum + 1; llocp->first_column = toknum + 1;

View File

@@ -429,7 +429,7 @@ static
res = input[toknum++]; res = input[toknum++];
]$2[;]AT_LOCATION_IF([[ ]$2[;]AT_LOCATION_IF([[
]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1; ]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1;
]AT_LOC_FIRST_COLUMN[ = ]AT_LOC_LAST_COLUMN[ = toknum;]])[ ]AT_LOC_FIRST_COLUMN[ = ]AT_LOC_LAST_COLUMN[ = ]AT_CXX_IF([(unsigned )], [(int)])[toknum;]])[
return res; return res;
}]dnl }]dnl
]) ])

View File

@@ -401,7 +401,7 @@ yylex (void)
static int static int
get_args (int argc, const char **argv) get_args (int argc, const char **argv)
{ {
int res; long res;
char *endp; char *endp;
assert (argc == 2); (void) argc; assert (argc == 2); (void) argc;
res = strtol (argv[1], &endp, 10); res = strtol (argv[1], &endp, 10);
@@ -409,7 +409,7 @@ get_args (int argc, const char **argv)
assert (0 <= res); assert (0 <= res);
assert (res <= INT_MAX); assert (res <= INT_MAX);
assert (errno != ERANGE); assert (errno != ERANGE);
return res; return (int) res;
} }
int int

View File

@@ -163,7 +163,7 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
[if (res) [if (res)
{ {
AT_VAL.ival = (res - '0') * 10; AT_VAL.ival = (res - '0') * 10;
AT_VAL.fval = (res - '0') / 10.f; AT_VAL.fval = (float) (res - '0') / 10.f;
}], }],
[30 0.3]) [30 0.3])