Avoid compiler warnings

At least GCC 7.3, with -O1 or -O2 (but not -O0 or -O3) generates
warnings with -Wnull-dereference when using yyformat: it fails to see
yyformat cannot be null.

Reported by Frank Heckenbach, https://savannah.gnu.org/patch/?9620.

* configure.ac: Use -Wnull-dereference if supported.
* data/glr.c, data/lalr1.cc, data/yacc.c: Define yyformat in such
a way that GCC cannot not see that yyformat is defined.
Using `default: abort();` also addresses the issue, but forces
the inclusion of `stdlib.h`, which we avoid.
This commit is contained in:
Akim Demaille
2018-05-12 13:21:24 +02:00
parent d132c2d545
commit 2b5a27ba3d
4 changed files with 4 additions and 1 deletions

View File

@@ -2086,6 +2086,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
case N: \
yyformat = S; \
break
default: /* Avoid compiler warnings. */
YYCASE_(0, YY_("syntax error"));
YYCASE_(1, YY_("syntax error, unexpected %s"));
YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));

View File

@@ -1077,6 +1077,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla],
case N: \
yyformat = S; \
break
default: // Avoid compiler warnings.
YYCASE_ (0, YY_("syntax error"));
YYCASE_ (1, YY_("syntax error, unexpected %s"));
YYCASE_ (2, YY_("syntax error, unexpected %s, expecting %s"));

View File

@@ -1207,6 +1207,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
case N: \
yyformat = S; \
break
default: /* Avoid compiler warnings. */
YYCASE_(0, YY_("syntax error"));
YYCASE_(1, YY_("syntax error, unexpected %s"));
YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));