From 32e5a91a91bc034a3f596c056569c0eaa09ca7e1 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 5 Oct 2019 22:51:16 +0200 Subject: [PATCH] yacc.c: work around warnings from G++ 4.8 input.c: In function 'int yyparse()': input.c: error: conversion to 'long int' from 'long unsigned int' may change the sign of the result [-Werror=sign-conversion] yyes_capacity = sizeof yyesa / sizeof *yyes; ^ cc1plus: all warnings being treated as errors * data/skeletons/yacc.c: here. --- TODO | 19 +++++++++++++++++++ data/skeletons/yacc.c | 8 ++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index f0ec27da..d99954e0 100644 --- a/TODO +++ b/TODO @@ -128,6 +128,25 @@ Rename these guys as "diagnostics.*" (or "diagnose.*"), since that's the name they have in gcc, clang, etc. Likewise for the complain_* series of functions. +* Modernization +Remove some casts made for old compilers, such as Clang++ 3.3 and 3.4 when +compiling yacc.c code: + + YYPTRDIFF_T yysize = (YYPTRDIFF_T) (yyssp - yyss + 1); + + YYPTRDIFF_T yysize_old = + *yytop == yytop_empty ? 0 : (YYPTRDIFF_T) (*yytop - *yybottom + 1); + + YYPTRDIFF_T yysize = (YYPTRDIFF_T) (yyesp - *yyes + 1); + +Or G++ 4.8 + + yyes_capacity = (YYPTRDIFF_T) (sizeof yyesa / sizeof *yyes); + +Or GCC 4.8 + + int input_elts = (int) (sizeof input / sizeof input[0]); + * Completion Several features are not available in all the backends. diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c index e4705735..abe20a5f 100644 --- a/data/skeletons/yacc.c +++ b/data/skeletons/yacc.c @@ -1154,10 +1154,10 @@ yytnamerr (char *yyres, const char *yystr) do_not_strip_quotes: ; } - if (! yyres) + if (yyres) + return (YYPTRDIFF_T) (yystpcpy (yyres, yystr) - yyres); + else return yystrlen (yystr); - - return yystpcpy (yyres, yystr) - yyres; } # endif @@ -1490,7 +1490,7 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[ yystacksize = YYINITDEPTH;]b4_lac_if([[ yyes = yyesa; - yyes_capacity = sizeof yyesa / sizeof *yyes; + yyes_capacity = (YYPTRDIFF_T) (sizeof yyesa / sizeof *yyes); if (YYMAXDEPTH < yyes_capacity) yyes_capacity = YYMAXDEPTH;]])[