Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit type conversion warnings #196

Closed
ruimaciel opened this issue Sep 20, 2017 · 1 comment

Comments

@ruimaciel
Copy link

commented Sep 20, 2017

While building re2c from source (v1.0.2) I've noticed that there are a couple of type conversion warnings popping out during the build process. Here are the warnings:

Warning #1:

rc/ast/parser.cc: In function ‘int yyparse(re2c::context_t&)’:
src/ast/parser.cc:1128:10: warning: conversion to ‘yytype_int16 {aka short int}’ from ‘int’ may alter its value [-Wconversion]
   *yyssp = yystate;
          ^

Here's a proposal to fix this warning, by changing the type of yystate (and yyn) to yytype_int16.
patch1.txt

Warning #2:

src/ast/parser.cc:1133:40: warning: conversion to ‘long unsigned int’ from ‘long int’ may change the sign of the result [-Wsign-conversion]
       YYSIZE_T yysize = yyssp - yyss + 1;

This warning, OTOH, may require some attention, as YYSIZE_T is an unsigned integer type but I believe there are no assurances that the result of (yyssp-yyss + 1) is always positive.

@skvadrik

This comment has been minimized.

Copy link
Owner

commented Sep 20, 2017

Hi Rui,

Thanks for the patch, but parser.cc is a bison-generated file, so fixing the warnings requires fixing bison.

I've seen these warnings ever since I enabled -Wconversion and -Wsign-conversion options, and that was 2 years ago. The majority of bison users either build without these warnings, or just ignore them. I reported this to bison mailing list and Akim Demaille replied that the conversion is safe, but he will address the warning at some point (or I am welcome to send a patch).

@skvadrik skvadrik closed this Mar 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.