This is the mail archive of the gcc@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: can't reinterpret_cast to/from the same type


On 08/09/2007, Joe Buck <Joe.Buck@synopsys.com> wrote:
>
> It still seems odd, and this restriction could make the coding of
> templates more complex.

Agreed, but I'm not sure making reinterpret_cast convenient to use is
a noble aim  :-)
It should be used a last resort, in the knowledge that the result is
implementation-defined.
Reinterpret_cast isn't generic, it only works with a subset of types,
which sounds to me like a definite case for a set of template
specialisations.  If needed anyone can write a reinterpret_cast
wrapper specialised for all the legal reinterpret_cast conversions, as
well as various int->long and int->int conversions if they want to
allow them.
So I don't think GCC needs to do anything. The standard is clear: "No
other conversion can be performed explicitly using reinterpret_cast."
so any GCC extension to reinterpret_cast would conflict with that. It
could also break code that used failure to compile a reinterpret_cast
as a form of static_assert (I don't know if anyone actually does
that.)

Jon


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