Public bug reported:

I wish to use the -Wconversion at gcc (the warnings are instructive for
me, and they already taught me a lot), but then:

$ bash bison_conversion_bug.sh 
y.tab.c: In function ‘yyparse’:
y.tab.c:1023:12: warning: conversion to ‘yytype_int16 {aka short int}’ from 
‘int’ may alter its value [-Wconversion]
   *yyssp = yystate;
            ^~~~~~~
y.tab.c:1028:25: warning: conversion to ‘long unsigned int’ from ‘long int’ may 
change the sign of the result [-Wsign-conversion]
       YYSIZE_T yysize = yyssp - yyss + 1;
                         ^~~~~
$

I get this problem even in an almost empty grammar and minimal C source
frame for it, see the attachment: an example for minimal grammar and
minimal C frame ALREADY providing the error.

This is the error in case of my Ubuntu 18.04 ( bison --version = 3.0.4,
gcc --version = (Ubuntu 7.3.0-12ubuntu1) 7.3.0).

I could try Debian jessie, where I get exactly the same error at exactly
the same line position ( bison --version = 3.0.2, gcc --version =
(Debian 4.9.2-10+deb8u1) 4.9.2).

MY SUGGESTION: IF the bison developers are sure, that "yystate" and
"yyssp - yyss + 1" will always fit into "short int" or "long unsigned
int", THEN an explicit casting could be a solution.  HOWEVER in case of
"yystate" it would be much more relaxing to make a decision whether it
should be an "int" or "short int".

The compilation commands are:

CCOPTS=''
CCOPTS+=' -std=c11'
CCOPTS+=' -Og -g'
CCOPTS+=' -Wabi'
CCOPTS+=' -Wfatal-errors'
CCOPTS+=' -Wall'
CCOPTS+=' -Wextra'
CCOPTS+=' -Wreturn-type'
CCOPTS+=' -Wconversion'  ### bison has 2 conversion errors
CCOPTS+=' -fexceptions'
CCOPTS+=' -pedantic-errors'
CCOPTS+=' -fmax-errors=1'

rm -f y.output y.tab.h y.tab.c y.tab.o
bison --yacc --verbose -d "EXAMPLE_GIVEN_IN_THE_ATTACHMENT.y"
gcc -c ${CCOPTS} y.tab.c

** Affects: gnome-settings-daemon (Ubuntu)
     Importance: Undecided
         Status: New

** Attachment added: "minimal grammar with minimal C frame"
   
https://bugs.launchpad.net/bugs/1758373/+attachment/5088332/+files/bison_conversion_bug.y

-- 
You received this bug notification because you are a member of Desktop
Packages, which is subscribed to gnome-settings-daemon in Ubuntu.
https://bugs.launchpad.net/bugs/1758373

Title:
  bison -Wconversion warning

Status in gnome-settings-daemon package in Ubuntu:
  New

Bug description:
  I wish to use the -Wconversion at gcc (the warnings are instructive
  for me, and they already taught me a lot), but then:

  $ bash bison_conversion_bug.sh 
  y.tab.c: In function ‘yyparse’:
  y.tab.c:1023:12: warning: conversion to ‘yytype_int16 {aka short int}’ from 
‘int’ may alter its value [-Wconversion]
     *yyssp = yystate;
              ^~~~~~~
  y.tab.c:1028:25: warning: conversion to ‘long unsigned int’ from ‘long int’ 
may change the sign of the result [-Wsign-conversion]
         YYSIZE_T yysize = yyssp - yyss + 1;
                           ^~~~~
  $

  I get this problem even in an almost empty grammar and minimal C
  source frame for it, see the attachment: an example for minimal
  grammar and minimal C frame ALREADY providing the error.

  This is the error in case of my Ubuntu 18.04 ( bison --version =
  3.0.4, gcc --version = (Ubuntu 7.3.0-12ubuntu1) 7.3.0).

  I could try Debian jessie, where I get exactly the same error at
  exactly the same line position ( bison --version = 3.0.2, gcc
  --version = (Debian 4.9.2-10+deb8u1) 4.9.2).

  MY SUGGESTION: IF the bison developers are sure, that "yystate" and
  "yyssp - yyss + 1" will always fit into "short int" or "long unsigned
  int", THEN an explicit casting could be a solution.  HOWEVER in case
  of "yystate" it would be much more relaxing to make a decision whether
  it should be an "int" or "short int".

  The compilation commands are:

  CCOPTS=''
  CCOPTS+=' -std=c11'
  CCOPTS+=' -Og -g'
  CCOPTS+=' -Wabi'
  CCOPTS+=' -Wfatal-errors'
  CCOPTS+=' -Wall'
  CCOPTS+=' -Wextra'
  CCOPTS+=' -Wreturn-type'
  CCOPTS+=' -Wconversion'  ### bison has 2 conversion errors
  CCOPTS+=' -fexceptions'
  CCOPTS+=' -pedantic-errors'
  CCOPTS+=' -fmax-errors=1'

  rm -f y.output y.tab.h y.tab.c y.tab.o
  bison --yacc --verbose -d "EXAMPLE_GIVEN_IN_THE_ATTACHMENT.y"
  gcc -c ${CCOPTS} y.tab.c

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gnome-settings-daemon/+bug/1758373/+subscriptions

-- 
Mailing list: https://launchpad.net/~desktop-packages
Post to     : desktop-packages@lists.launchpad.net
Unsubscribe : https://launchpad.net/~desktop-packages
More help   : https://help.launchpad.net/ListHelp

Reply via email to