------- Comment #2 from tom at atoptech dot com  2009-02-12 18:10 -------
Subject: Re:  -Wconversion useless

You miss the point. The only way to assign a non-constant value to a bit
field outside of a struct is using an integral variable i.e.,

struct foo
{
    int a : 2;
};

void assign( struct foo v, int x )
{
    v.a = x;
}

This results automatically in a warning. How do code this assignment
type-safe? There is no (bit-field) cast operator in the C or C++.

Like the "gcc" code base, our code does a lot bit-field assignments. We
no get thousands of warning using -Wconversion, this behavior makes the
option useless.

Again, compile the "gcc" code-base with "-Wconversion" and then you will
understand the problem.

Expect for bit-fields which are problematic to do potential bit-loss
(you must use with caution), you want warnings for implicit narrowing if
values, e.g., (double -> int)

void foo( int x );

...

double n;
foo(n)

The old behavior was just fine!

I'm sure many people do not even realize they are NOT getting implicit
conversions warnings anymore because they are not caught by "-Wall"
anymore. We only discovered this be tracing a bug in our code! We then
turned on "-Wconversion" only to discover thousands of warnings with no
way practical way to fix them. 

Regards,

Tom Geocaris

On Thu, 2009-02-12 at 17:39 +0000, pinskia at gcc dot gnu dot org wrote:
> 
> ------- Comment #1 from pinskia at gcc dot gnu dot org  2009-02-12 17:39 
> -------
> Really -Wconversion is correct to warn about bit-fields because the conversion
> will lose bits.
> 
> 


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170

Reply via email to