Skip to content

yacc.c raises warnings with -std=c89 -pedantic #109

@GitMensch

Description

@GitMensch

The reason is

bison/data/skeletons/yacc.c

Lines 2008 to 2009 in 25b3d0e

yypcontext_t yyctx
= {]b4_push_if([[yyps]], [[yyssp]b4_lac_if([[, yyesa, &yyes, &yyes_capacity]])])[, yytoken]b4_locations_if([[, &yylloc]])[};

which leads to a generation of

        yypcontext_t yyctx
          = {yyssp, yytoken};
        char const *yymsgp = YY_("syntax error");
        int yysyntax_error_status;
        yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);

and therefore raises

parser.c:24521:14: warning: initializer element is not computable at load time [-Wpedantic]
24521 |           = {yyssp, yytoken};
      |              ^~~~~
parser.c:24521:21: warning: initializer element is not computable at load time [-Wpedantic]
24521 |           = {yyssp, yytoken};
      |                     ^~~~~~~

Changing the generated code as follows:

        yypcontext_t yyctx;
        char const *yymsgp = YY_("syntax error");
        int yysyntax_error_status;
        yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);
        yyctx.yyssp = yyssp;
        yyctx.yytoken = yytoken;
        yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);

fixes the code, but sadly that is not easily replaced by defining some macros.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions