gcc4 warnings -Wuninitialized -Wfloat-equal and -Wconversion

Jaime Torres jtamate at gmail.com
Tue Sep 22 21:18:08 BST 2009


On Tuesday 22 September 2009 18:03:47 David Faure wrote:
> On Monday 14 September 2009, Jaime Torres wrote:
> > On Monday 14 September 2009 11:41:18 David Faure wrote:
> > > But I don't know how to fix the warnings that come from member vars
> > > that use bitfields though.
> >
> > This is what I've found:
> >
> > Use of signed:1 bit-fields is usually a mistake in the code, since the
> > user doesn't normally intend to use values 0 and -1. Warning if 1 might
> > be stored in such a bit-field seems appropriate for -Wconversion.
> 
> But I get warnings even with unsigned bitfields:
> src/gui/text/qtextoption.h:97: warning: conversion to 'unsigned char:1'
>  from 'uint' may alter its value
> 
> The line is
> inline void setTextDirection(Qt::LayoutDirection aDirection) {
>  this->direction = aDirection; }
> 
> The types are defined as
> 
>     enum LayoutDirection {
>         LeftToRight,
>         RightToLeft
>     };

I've done a simple test and this is what I've found:

tes1t.cpp:20: aviso: la conversión de ‘unsigned char:1’ desde ‘unsigned int’ puede alterar su valor

using a struct like this:

typedef enum {
        LeftToRight,
        RightToLeft
} LayoutDirection_T;

typedef struct
{
	LayoutDirection_T b:1;
}
LayoutDirection;

test2.cpp compiles cleanly.

>    uint direction : 1;
> 
> I tried uint(aDirection), static_cast<uint>(aDirection), and
>  static_cast<uchar>(aDirection), no difference.
> It looks like it wants static_cast<uchar:1>(aDirection) but that syntax
>  doesn't exist :-)
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test1.cpp
Type: text/x-c++src
Size: 327 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090922/56733bff/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.cpp
Type: text/x-c++src
Size: 327 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090922/56733bff/attachment-0001.cpp>


More information about the kde-core-devel mailing list