Hello,

On Sun, Apr 07 2019, ashwina kumar wrote:
> Hi ,
>
> While working I just figured out that -Wconversion is buggy. Please see the
> below code- -
>
> $ cat b.c
> #include <stdint.h>
>
> void main (void)
> {
>         //contains build errors
>         uint16_t x = 1;
>         uint16_t y = 2;
>         y += x;  /* contains error */
>
> }
>
> $ gcc b.c -Wconversion
> b.c: In function ‘main’:
> b.c:22:7: warning: conversion to ‘uint16_t {aka short unsigned int}’
> from ‘int’ may alter its value [-Wconversion]
>   y += x;  /* contains error */
>
> Please help me to know as an GSOC student can I work on this for this year
> to make -Wconversion more robust.

Unfortunately I am not quite sure what you think is a problem.  The
option -Werror warns "for implicit conversions that may alter a value."
In this case, the C language mandates that the addition is performed in
full integer type, which is then stored to a shorter type, which is a
conversion which may alter the value.  Thus the warning.

In this particular example the values are known constants and so one
could argue that the result of addition is known at compile not to
exceed the uint16_t range.  However, the infrastructure that would have
to be added to the C/C++ front-ends to perform such value tracking would
not be justified with this simple use-case - especially given that the
warning should be perfectly silence-able with an explicit conversion.

Therefore, we are very unlikely to accept such GSoC proposal, sorry.

Martin

Reply via email to