[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: gcc4 warnings -Wuninitialized -Wfloat-equal and -Wconversion
From: Jaime Torres <jtamate () gmail ! com>
Date: 2009-09-22 20:18:08
Message-ID: 200909222218.10367.jtamate () gmail ! com
[Download RAW message or body]
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 :-)
>
["test1.cpp" (text/x-c++src)]
typedef enum {
LeftToRight,
RightToLeft
} LayoutDirection_T;
typedef struct
{
LayoutDirection_T b:1;
}
LayoutDirection;
struct A
{
unsigned int direction:1;
inline void setTextDirection(LayoutDirection_T aDirection)
{
direction = aDirection;
}
};
int main(int argc,char **argv)
{
return 0;
}
["test2.cpp" (text/x-c++src)]
typedef enum {
LeftToRight,
RightToLeft
} LayoutDirection_T;
typedef struct
{
LayoutDirection_T b:1;
}
LayoutDirection;
struct A
{
unsigned int direction:1;
inline void setTextDirection(LayoutDirection aDirection)
{
direction = aDirection.b;
}
};
int main(int argc,char **argv)
{
return 0;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic