This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix const pointer warning in gthr-win32.h


This patch fixes a warning about casting away pointer constness.

It was necessary to copy the CONST_CAST definition to tsystem.h since this file cannot include system.h.

This patch was tested by a bootstrap on i386-pc-mingw32.

OK to commit?

2008-07-10  Aaron W. LaFramboise  <aaronavay62@aaronwl.com>

	* gcc/tsystem.h (CONST_CAST, CONST_CAST2): Duplicate from system.h.
	* gcc/gthr-win32.h (__gthread_setspecific): Use CONST_CAST.

Index: gcc/gthr-win32.h
===================================================================
--- gcc/gthr-win32.h	(revision 137703)
+++ gcc/gthr-win32.h	(working copy)
@@ -612,7 +612,10 @@ __gthread_getspecific (__gthread_key_t k
 static inline int
 __gthread_setspecific (__gthread_key_t key, const void *ptr)
 {
-  return (TlsSetValue (key, (void*) ptr) != 0) ? 0 : (int) GetLastError ();
+  if (TlsSetValue (key, CONST_CAST(void *, ptr)) != 0)
+    return 0;
+  else
+    return GetLastError ();
 }
 
 static inline void
Index: gcc/tsystem.h
===================================================================
--- gcc/tsystem.h	(revision 137703)
+++ gcc/tsystem.h	(working copy)
@@ -131,6 +131,16 @@ extern int errno;
    unreachable default case of a switch.  Do not use gcc_assert(0).  */
 #define gcc_unreachable() (abort ())
 
+/* This is a copy of CONST_CAST from system.h */
+
+#if defined(__GNUC__) && GCC_VERSION != 4000
+/* GCC 4.0.x has a bug where it may ICE on this expression.  */
+#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((__extension__(union {FROMTYPE _q; TOTYPE _nq;})(X))._nq)
+#else
+#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((TOTYPE)(FROMTYPE)(X))
+#endif
+#define CONST_CAST(TYPE,X) CONST_CAST2(TYPE, const TYPE, (X))
+
 /* Filename handling macros.  */
 #include "filenames.h"
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]