freetype-devel
[Top][All Lists]
Advanced

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

Re: [ft-devel] g++ 4.5.0 and type punning issues (again, sigh)


From: malc
Subject: Re: [ft-devel] g++ 4.5.0 and type punning issues (again, sigh)
Date: Mon, 12 Jul 2010 20:23:07 +0400 (MSD)
User-agent: Alpine 2.00 (LNX 1167 2008-08-23)

On Sun, 11 Jul 2010, Werner LEMBERG wrote:

> 
> Folks,
> 
> 
> it seems that g++ 4.5.0 is ridiculously picky w.r.t. type-punning:
> While previous g++ versions have been made silent successfully, the
> latest version reports zillions of warnings.
> 
> The code hasn't changed basically; all warnings stem from macros like
> `FT_NEW' or `FT_NEW_ARRAY', and IMHO there are definitely *no*
> type-punning issues since it is always related to type-converting
> malloc's `void *' return value, and this should be harmless AFAIK.
> 
> Anybody on the list who has more insight, probably be able to suggest
> a fix which we could apply to the git repository?
> 
> To see the warnings, say
> 
>   sh autogen.sh
>   ./configure CC=g++
>   make
> 
> within a clean copy of the git repository.

I've asked Richard Henderson about this, and his conclusion is:
a. the code is broken
b. following fixes it

diff --git a/include/freetype/internal/ftmemory.h 
b/include/freetype/internal/ftmemory.h
index 2010ca9..e053290 100644
--- a/include/freetype/internal/ftmemory.h
+++ b/include/freetype/internal/ftmemory.h
@@ -64,7 +64,11 @@ FT_BEGIN_HEADER
    */
 
 #ifdef __cplusplus
-#define FT_ASSIGNP( p, val )  *((void**)&(p)) = (val)
+extern "C++" template<typename T> inline T * my_typeof( T *, void *v )
+{
+    return static_cast<T*>(v);
+}
+#define FT_ASSIGNP( p, val ) p = my_typeof( p, val )
 #else
 #define FT_ASSIGNP( p, val )  (p) = (val)
 #endif

Following helps full with another issue.

diff --git a/src/tools/apinames.c b/src/tools/apinames.c
index 7f191e1..f96bcf6 100644
--- a/src/tools/apinames.c
+++ b/src/tools/apinames.c
@@ -152,7 +152,7 @@ names_dump( FILE*         out,
       {
         /* we must omit the .dll suffix from the library name */
         char   temp[512];
-        char*  dot;
+        const char*  dot;
 
         if ( dll_name == NULL )
         {


FWIW even plain gcc (4.5 or not) will emit tons of warnings when
invoked with -fstrict-aliasing -Wstrict-aliasing=[2|3].

-- 
mailto:address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]