#128 g++ -Wconversion

2.6.0
closed
5
2016-02-27
2011-06-09
H Johansson
No

On amd64, where int != size_t, gcc (4.4) with -Wconversion gives some warnings. (I'm using -Wconversion as it helps me avoid mistakes in the C code embedded by the lexer.)

<stdout>: In function ‘int yylex()’:
<stdout>:947: error: conversion to ‘YY_CHAR’ from ‘int’ may alter its value
<stdout>:957: error: conversion to ‘YY_CHAR’ from ‘int’ may alter its value
<stdout>:973: error: conversion to ‘int’ from ‘size_t’ may alter its value
<stdout>: In function ‘int yy_get_next_buffer()’:
<stdout>:1591: error: conversion to ‘int’ from ‘yy_size_t’ may alter its value
<stdout>:1604: error: conversion to ‘int’ from ‘yy_size_t’ may alter its value
<stdout>:1626: error: conversion to ‘int’ from ‘yy_size_t’ may alter its value
<stdout>:1634: error: conversion to ‘int’ from ‘ssize_t’ may alter its value
<stdout>: In function ‘yy_state_type yy_get_previous_state()’:
<stdout>:1687: error: conversion to ‘YY_CHAR’ from ‘int’ may alter its value
<stdout>:1697: error: conversion to ‘YY_CHAR’ from ‘int’ may alter its value
<stdout>: In function ‘yy_state_type yy_try_NUL_trans(yy_state_type)’:
<stdout>:1725: error: conversion to ‘YY_CHAR’ from ‘int’ may alter its value
<stdout>: In function ‘void yyunput(int, char*)’:
<stdout>:1757: error: conversion to ‘int’ from ‘yy_size_t’ may alter its value
<stdout>: In function ‘int yyinput()’:
<stdout>:1798: error: conversion to ‘int’ from ‘long int’ may alter its value
<stdout>: In function ‘void yyensure_buffer_stack()’:
<stdout>:2106: error: conversion to ‘int’ from ‘size_t’ may alter its value
<stdout>: In function ‘yy_buffer_state* yy_scan_buffer(char*, yy_size_t)’:
<stdout>:2144: error: conversion to ‘int’ from ‘yy_size_t’ may alter its value
<stdout>: In function ‘yy_buffer_state* yy_scan_string(const char*)’:
<stdout>:2166: error: conversion to ‘int’ from ‘size_t’ may alter its value

Worked around by piping the generated lexer through (I hope more or less correct fixes):

sed -e "s/typedef unsigned char YY_CHAR/typedef int YY_CHAR/" \ -e "s/int yyleng;/size_t yyleng;/" \ -e "s/int yyl;/size_t yyl;/" \ -e "s/int yy_n_chars;/size_t yy_n_chars;/" \ -e "s/int num_to_alloc;/size_t num_to_alloc;/" \ -e "s/int num_to_read =/size_t num_to_read =/" \ -e "s/int new_size =/size_t new_size =/" \ -e "s/int offset =/size_t offset =/" \ -e "s/int number_to_move =/int number_to_move = (int)/" \ -e "s/yy_scan_bytes\(.*\)int /yy_scan_bytes\\1size_t /" \ -e "s/return yyleng/return (int) yyleng/" \ -e "s/i < _yybytes_len/i < (int) _yybytes_len/" \

resulting diff is attached.

Discussion

  • H Johansson

    H Johansson - 2011-06-09

    diff from the workarounds

     
    Attachments
  • Carla Bruni

    Carla Bruni - 2011-11-29

    I'm having the same problem with Visual Studio compiler:
    NPCScriptLexer.c(615) : warning C4244: 'initializing' : conversion from 'int' to 'YY_CHAR', possible loss of data

    I'm using flex 2.5.4.

    It would be nice at least to know if ignoring this warning is safe.

     
  • Will Estes

    Will Estes - 2012-03-23
    • assigned_to: nobody --> wlestes
     
  • Will Estes

    Will Estes - 2012-11-01
    • status: open --> open-accepted
     
  • Will Estes

    Will Estes - 2015-11-18
    • Group: 2.5.35 --> 2.6.0
     
  • Will Estes

    Will Estes - 2016-02-27
    • status: open-accepted --> closed
     
  • Will Estes

    Will Estes - 2016-02-27
        This is subsumed under https://github.com/westes/flex/issues/62
    
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks