From 9434571f950bbc2cbc6287f0c709ff69dcfcae7b Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 29 Mar 2020 09:49:23 +0200 Subject: [PATCH] yacc.c: revert to not using yysymbol_type_t in the yytranslate table This triggers warnings with several compilers. For instance ICC fills the logs with pages and pages of input.c(477): error: a value of type "int" cannot be used to initialize an entity of type "const yysymbol_type_t={yysymbol_type_t}" 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, ^ input.c(477): error: a value of type "int" cannot be used to initialize an entity of type "const yysymbol_type_t={yysymbol_type_t}" 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, ^ And so does G++9 when compiling yacc.c's (C) output input.c:545:8: error: invalid conversion from 'int' to 'yysymbol_type_t' [-fpermissive] 545 | 0, 5, 9, 2, 2, 2, 2, 2, 2, 2, | ^ | | | int input.c:545:15: error: invalid conversion from 'int' to 'yysymbol_type_t' [-fpermissive] 545 | 0, 5, 9, 2, 2, 2, 2, 2, 2, 2, | ^ | | | int Clang++ is no exception input.c:545:8: error: cannot initialize an array element of type 'const yysymbol_type_t' with an rvalue of type 'int' 0, 5, 9, 2, 2, 2, 2, 2, 2, 2, ^ input.c:545:15: error: cannot initialize an array element of type 'const yysymbol_type_t' with an rvalue of type 'int' 0, 5, 9, 2, 2, 2, 2, 2, 2, 2, ^ At some point we could use yysymbol_type_t's enumerators to define yytranslate. Meanwhile... * data/skeletons/yacc.c (yytranslate): Use the original integral type to define it. (YYTRANSLATE): Cast the result into yysymbol_type_t. --- data/skeletons/yacc.c | 10 ++++++---- tests/regression.at | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c index d9ded757..d70362ee 100644 --- a/data/skeletons/yacc.c +++ b/data/skeletons/yacc.c @@ -631,13 +631,15 @@ union yyalloc /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM as returned by yylex, with out-of-bounds checking. */ ]b4_api_token_raw_if(dnl -[[#define YYTRANSLATE(YYX) (YYX)]], -[[#define YYTRANSLATE(YYX) \ - (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYSYMBOL_YYUNDEF) +[[#define YYTRANSLATE(YYX) YY_CAST (yysymbol_type_t, YYX)]], +[[#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_type_t, yytranslate[YYX]) \ + : YYSYMBOL_YYUNDEF) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex. */ -static const yysymbol_type_t yytranslate[] = +static const ]b4_int_type_for([b4_translate])[ yytranslate[] = { ]b4_translate[ };]])[ diff --git a/tests/regression.at b/tests/regression.at index fa059248..cd79b507 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -665,7 +665,7 @@ AT_BISON_CHECK([-v -o input.c input.y]) [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c] AT_CHECK([[cat tables.c]], 0, -[[static const yysymbol_type_t yytranslate[] = +[[static const yytype_int8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,