bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Error in bison GLR C++ skeleton when using "%locations" & "%define parse


From: Tom Shields
Subject: Error in bison GLR C++ skeleton when using "%locations" & "%define parse.error custom" directives
Date: Tue, 10 Aug 2021 20:17:29 -0500

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]

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.

The fix is to either change the return type of “yypcontext_location” to “const 
YYLTYPE *”, or add a cast “(YYLTYPE *)” to the return expression.

Regards,

Tom Shields
214-287-9093
tom@ojodeagua.com

Powered by Mailbutler, the email extension that does it all: 
https://www.mailbutler.io


reply via email to

[Prev in Thread] Current Thread [Next in Thread]