warning: conversion to ‘unsigned int:31’ from ‘unsigned int’ may alter its value [-Wconversion]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
 
i'd like to add -Wconversion to my build flags but it warns for (smaller type) bitfields assignments.
manual says that it shouldn't warn for explicit casts but there're any notes about explicit casts
to smaller bitfield types. finally, the current gcc-4.8.x reports a warning:
 
struct X { unsigned field : 31; };
int main()
{
        unsigned u = 0u;
        X x = { .field = static_cast< typeof( X::field ) >( u ) };
        return x.field;
}
 
 
$ g++ u.cpp -O2 -c -Wall -Wconversion
u.cpp: In function ‘int main()’:
u.cpp:6:58: warning: conversion to ‘unsigned int:31’ from ‘unsigned int’ may alter its value [-Wconversion]
  X x = { .field = static_cast< typeof( X::field ) >( u ) };
                                                          ^
 
is it a bug in gcc or an improper cast from my side?
 
BR,
Paweł.





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux