[PATCH INSTALLED]: delete some const shadow functions

Richard Guenther richard.guenther@gmail.com
Sat Sep 1 21:02:00 GMT 2007


On 9/1/07, Kaveh R. GHAZI <ghazi@caip.rutgers.edu> wrote:
> On Sat, 1 Sep 2007, Richard Guenther wrote:
>
> > Now, the CONST_CAST macro as is is worse than the C++ counterpart.
> > For const_cast<> you have to specify the type you cast to while for
> > CONST_CAST you just magically strip it by casting to void*.  Which
> > leads to the following only possibility to implement it with C++...
> >
> > #if defined(__cplusplus)
> > template <class T>
> > struct no_const_trait { typedef T Type; };
> > template <class T>
> > struct no_const_trait<const T *> { typedef T* Type; };
> > template <class T>
> > typename no_const_trait<T>::Type CONST_CAST (T x)
> >  { return const_cast<typename no_const_trait<T>::Type>(x); }
> > #else
> > ...
> > #endif
> >
> > not exactly the nicest variant.
> > Richard.
>
> If I add a TYPE argument to the CONST_CAST macro, would that address your
> concern?  Then I believe the C++ clause would become just
> const_cast<TYPE>(ARG), assuming const_cast pacifies -Wcast-qual.

Yes, I would certainly find this more appropriate.  But of course
others opinion may differ here ;)  It would also allow to make the
macro implementation stricter by using union { const TYPE q; TYPE v; }.

Richard.



More information about the Gcc-patches mailing list