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]

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


Kaveh R. GHAZI wrote:
On Thu, 10 Jul 2008, Aaron W. LaFramboise wrote:

--- gcc/tsystem.h	(revision 137703)
+++ gcc/tsystem.h	(working copy)

+/* This is a copy of CONST_CAST from system.h */

Files including tsystem.h are always compiled with the latest GCC you just
built.  So only the first CONST_CAST2 is needed, you can get rid of the
#ifdef wrapping for version 4.0.

OK, I discovered this file is also used in other places outside of GCC such as in libgfortran, so using tsystem.h is not OK there. What is the proper way to make this error go away then, as I understand the union trick is the only way to silence it?



By the way, I think this prototype is actually incorrect. The ptr parameter really should not be const, because __gthread_getspecific returns a non-const void *. However, I'm not sure if there's some other reason this should be const; does anyone know about this?


Is it OK just to define this macro right here and use it, like this?


Index: gcc/gthr-win32.h
===================================================================
--- gcc/gthr-win32.h    (revision 138215)
+++ gcc/gthr-win32.h    (working copy)
@@ -609,10 +609,17 @@ __gthread_getspecific (__gthread_key_t k
  return ptr;
}

+/* This is a copy of CONST_CAST from system.h */
+#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((__extension__(union {FROMTYPE _q; \
+  TOTYPE _nq;})(X))._nq)
+
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_CAST2(void *, const void *, ptr)) != 0)
+    return 0;
+  else
+    return GetLastError ();
}

static inline void


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