Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#115 G++ -W produces "warning: unused parameter ‘yyscanner’"

open
nobody
5
2012-08-02
2010-01-04
Anonymous
No

I'm using flex 2.5.35 on MacOS 10.6.2, and I like to use -W and -Wall whenever possible to find bugs. However, the generated scanner won't compile warning-free against g++ 4.2.1:

%{
#include <iostream>
using namespace std;
%}

%option reentrant
%option noyywrap
%option nounput
%option noinput

DIGIT [0-9]
ID [a-z][a-z0-9]*

%%

[(){}+*?.|\[\]] cout << "Symbol: " << yytext << endl;
[ \t\n]+
{ID} cout << "ID: " << yytext << endl;
. cout << "Unknown: " << yytext << endl;
%%

int main(int argc, char *argv[])
{
yyscan_t scanner;

yylex_init(&scanner);

if (argv[1]) {
yy_scan_string(argv[1], scanner);
}
yylex(scanner);
yylex_destroy(scanner);

return 0;
}

% flex example.l
% g++ -g -O -W -Wall -o re lex.yy.c
lex.yy.c: In function ‘int yy_get_next_buffer(void*)’:
lex.yy.c:1004: warning: comparison between signed and unsigned integer expressions
lex.yy.c: At global scope:
lex.yy.c:1546: warning: unused parameter ‘yyscanner’
lex.yy.c:1866: warning: unused parameter ‘yyscanner’
lex.yy.c:1871: warning: unused parameter ‘yyscanner’
lex.yy.c:1883: warning: unused parameter ‘yyscanner’

Discussion

  • Thanks for the report. Unfortunately, at the moment flex.skl's m4 logic for non-ANSI declarations is so tangled that there isn't an *easy* fix for the problem.

     
    • labels: 595149 --> Warning messages
    • assigned_to: nobody --> scfc_de
    • status: open --> open-later
     
  • On second thought, flex already unconditionally produces ANSI declarations, so there is no need to hang on to the tangled m4 logic. I'll write up a patch later.

     
  • Will Estes
    Will Estes
    2012-08-02

    • assigned_to: scfc_de --> nobody
    • status: open-later --> open
     
  • cmeumeu
    cmeumeu
    2012-12-25

    I ran into the same situation as. Here's the workaround I came up with:

    * for the last 3 warning (yyalloc, yyfree and yyrealloc). I used "%noyyalloc", "%noyyfree", "%noyyrealloc" and redefined them myself in the last portion of the flex source:

    void xlang_free (void * ptr, yyscan_t yyscanner)
    {
    (void)yyscanner;
    free(ptr);
    }

    void *xlang_alloc (yy_size_t size, yyscan_t yyscanner)
    {
    (void)yyscanner;
    return malloc(size);
    }

    void *xlang_realloc (void * ptr, yy_size_t size, yyscan_t yyscanner)
    {
    (void)yyscanner;
    return realloc(ptr, size );
    }

    * For the first one (yy_fatal_error), I redefined YY_EXIT_FAILURE to "( (void)yyscanner, 2 )".

    This got me through the compilation using -Werror -Wall -Wextra

    Anyway, I though I'd share...

    Cédric