From 5973d763c0867924830fa90f6560078f745d45a7 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 5 Oct 2019 17:35:40 +0200 Subject: [PATCH] yacc.c: work around warnings from Clang++ 3.3 and 3.4 When we run the test suite with these C++ compilers to compile C code, we get: 239. synclines.at:440: testing syncline escapes: yacc.c ... ../../tests/synclines.at:440: $CC $CFLAGS $CPPFLAGS \"\\\"\".c -o \"\\\"\" || exit 77 stderr: stdout: ../../tests/synclines.at:440: COLUMNS=1000; export COLUMNS; bison --color=no -fno-caret -o \"\\\"\".c \"\\\"\".y ../../tests/synclines.at:440: $CC $CFLAGS $CPPFLAGS $LDFLAGS -o \"\\\"\" \"\\\"\".c $LIBS stderr: "\"".c:1102:41: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32] YYPTRDIFF_T yysize = yyssp - yyss + 1; ~~~~~~ ~~~~~~~~~~~~~^~~ 1 error generated. 193. conflicts.at:545: testing parse.error=verbose and consistent errors: lr.type=canonical-lr parse.lac=full ... input.c:737:75: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32] YYPTRDIFF_T yysize_old = *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1; ~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~^~~ input.c:901:48: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32] YYPTRDIFF_T yysize = yyesp - *yyes + 1; ~~~~~~ ~~~~~~~~~~~~~~^~~ * data/skeletons/yacc.c: Add more casts. --- data/skeletons/yacc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c index fdf4ba6d..e4705735 100644 --- a/data/skeletons/yacc.c +++ b/data/skeletons/yacc.c @@ -856,7 +856,8 @@ yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd, yy_state_num *yybottom_no_free, yy_state_num **yytop, yy_state_num *yytop_empty) { - YYPTRDIFF_T yysize_old = *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1; + YYPTRDIFF_T yysize_old = + *yytop == yytop_empty ? 0 : (YYPTRDIFF_T) (*yytop - *yybottom + 1); YYPTRDIFF_T yysize_new = yysize_old + yyadd; if (*yycapacity < yysize_new) { @@ -1023,7 +1024,7 @@ yy_lac (yy_state_num *yyesa, yy_state_num **yyes, YYDPRINTF ((stderr, " R%d", yyrule - 1)); if (yyesp != yyes_prev) { - YYPTRDIFF_T yysize = yyesp - *yyes + 1; + YYPTRDIFF_T yysize = (YYPTRDIFF_T) (yyesp - *yyes + 1); if (yylen < yysize) { yyesp -= yylen; @@ -1534,7 +1535,7 @@ yysetstate: #else { /* Get the current used size of the three stacks, in elements. */ - YYPTRDIFF_T yysize = yyssp - yyss + 1; + YYPTRDIFF_T yysize = (YYPTRDIFF_T) (yyssp - yyss + 1); # if defined yyoverflow {