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 INSTALLED]: delete some const shadow functions


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.

		--Kaveh
--
Kaveh R. Ghazi			ghazi@caip.rutgers.edu


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