Hi Tom, > Le 11 août 2021 à 03:17, Tom Shields <thomas.evans.shie...@icloud.com> a > écrit : > > The parser generated when using the “%locations” & “%define parse.error > custom” directives gets a warning using the bison C skeleton, but gets an > error using the C++ skeleton. > > Offending context: > ======================================================================== > /* The location of the lookahead of this context. */ > static YYLTYPE * > yypcontext_location (const yyGLRStack *yystackp) YY_ATTRIBUTE_UNUSED; > > static YYLTYPE * > yypcontext_location (const yyGLRStack *yystackp) > { > YY_USE (yystackp); > return &yylloc; /* <-- the error location: "yylloc” is a macro defined > as “(yystackp->yyval)” */ > } > ======================================================================== > Using the C skeleton: > macOS gcc: warning: returning 'const YYLTYPE *' (aka 'const struct YYLTYPE > *') from a function with result type 'YYLTYPE *' (aka 'struct YYLTYPE *') > discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers] > GNU gcc: warning: return discards 'const' qualifier from pointer target type > [-Wdiscarded-qualifiers]
Thanks for the report. I'm installing the following fix, which will show in the forthcoming 3.8 release. commit c2ba260487927a4cdf061fae10fdd1b387ca3d95 Author: Akim Demaille <akim.demai...@gmail.com> Date: Wed Aug 11 17:41:27 2021 +0200 glr.c: fix signature when using custom error messages Reported by Tom Shields <thomas.evans.shie...@icloud.com>. * data/skeletons/glr.c (yypcontext_location): Fix return type. * tests/calc.at: Check the case pure, location, custom error messages. diff --git a/TODO b/TODO index d9277255..de240dda 100644 --- a/TODO +++ b/TODO @@ -185,6 +185,8 @@ Line -1 and -3 should mention CATEGORIE, not CATEGORY. * Bison 3.8 ** Rewrite glr.cc (currently glr2.cc) +*** custom error messages + *** Remove jumps We can probably replace setjmp/longjmp with exceptions. That would help tremendously other languages such as D and Java that probably have no diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c index 117c996b..fab3733f 100644 --- a/data/skeletons/glr.c +++ b/data/skeletons/glr.c @@ -2174,10 +2174,10 @@ yypcontext_token (const yyGLRStack *yystackp) } ]b4_locations_if([[/* The location of the lookahead of this context. */ -static YYLTYPE * +static const YYLTYPE * yypcontext_location (const yyGLRStack *yystackp) YY_ATTRIBUTE_UNUSED; -static YYLTYPE * +static const YYLTYPE * yypcontext_location (const yyGLRStack *yystackp) { YY_USE (yystackp); diff --git a/tests/calc.at b/tests/calc.at index cd4b50a1..47ef720c 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -1469,6 +1469,8 @@ m4_define([AT_CHECK_CALC_GLR_CC], AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %verbose]) AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %define api.token.prefix {TOK_} %verbose]) +AT_CHECK_CALC_GLR_CC([%define parse.error custom %locations %header %name-prefix "calc" %verbose]) + AT_CHECK_CALC_GLR_CC([%locations %header %define parse.error verbose %debug %name-prefix "calc" %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}]) AT_CHECK_CALC_GLR_CC([%locations %header %define parse.error verbose %debug %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}]) > Using the C++ skeleton: > macOS g++: error: cannot initialize return object of type > 'yy::parser::location_type *' (aka ‘yy::location *') with an rvalue of type > ‘const yy::parser::location_type *' (aka 'const yy::location *’) > GNU g++: error: invalid conversion from 'const location_type*' {aka 'const > yy::location*'} to 'yy::parser::location_type*' {aka 'yy::location*'} > [-fpermissive] > ======================================================================== > > The error in the bison skeleton has been around for years; I vaguely recall > it showing up in a version of bison predating the addition of “%define > parse.error custom”. It isn’t a problem using the C skeleton, as I just turn > off the warning message, but I want to switch to using the C++ skeleton and > the C++ compiler error is, obviously, a show stopper. This is going to be tricky: glr.cc does not support custom error messages. We need someone to port these changes, if you are interested. Note that we are slowly phasing glr.cc out, to be replaced by glr2.cc, which is fully in C++, but for lack of time, it does not support custom error messages either. But it will be higher priority than glr.cc. Still, good wills will always be welcome! Cheers.