Re: type-punning warnings with optimizations turned on?
- From: jcupitt gmail com
- To: "Alan M. Evans" <gtkappdevellist alanevans org>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: type-punning warnings with optimizations turned on?
- Date: Fri, 6 Jul 2007 16:47:08 +0100
On 7/5/07, Alan M. Evans <gtkappdevellist alanevans org> wrote:
But with optimizations on (actually, at or above -O2), I get warnings
about type-punning on the calls to g_static_mutex_lock/unlock:
g++ -O2 -Wall -c `pkg-config --cflags glib-2.0` test.cpp
test.cpp: In function 'void MyMutex_lock(MyMutex*)':
test.cpp:19: warning: type-punning to incomplete type might break strict-aliasing rules
I think this is a gcc 4.1 issue. I found I couldn't cast from a Thing
*x[] to a void ** in one step without triggering a warning like this.
If I cast to void* and then to void **, all was well.
Anyway, insert a mysterious extra cast and the warnings vanish. Try
compiling this with -O2 -Wall and you'll see only one line triggers a
warning.
============
void
test (void **base)
{
}
int
main ()
{
int *thing[3];
test ((void **) thing);
test ((void **) ((void *) thing));
return (0);
}
==============
(now someone will tell me the compiler is correct and casting "int
*x[]" to "void **" is indeed wrong :-)
John
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]