I have a patch that presumably should fix BitCast compilation related
issues once and for all. I thought we've applied it long ago.
Can you try it Ryan?
--
Vyacheslav Egorov
On Thu, Jan 6, 2011 at 8:08 PM, <[email protected]> wrote:
> Eric, this could be merged without the BitCast change - it's not really
> related
> to Solaris but rather old GCC. I can try to get that in in a separate patch.
>
> http://codereview.chromium.org/5968004/
>
> --
> v8-dev mailing list
> [email protected]
> http://groups.google.com/group/v8-dev
>
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
diff --git a/src/utils.h b/src/utils.h
index 21e70d7..219343b 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -760,20 +760,32 @@ static inline int TenToThe(int exponent) {
// you can use BitCast to cast one pointer type to another. This confuses gcc
// enough that it can no longer see that you have cast one pointer type to
// another thus avoiding the warning.
+
+// We need different implementations of BitCast for pointer and non-pointer
+// values. We use partial specialization of auxiliary struct to work around
+// issues with template functions overloading.
template <class Dest, class Source>
-inline Dest BitCast(const Source& source) {
- // Compile time assertion: sizeof(Dest) == sizeof(Source)
- // A compile error here means your Dest and Source have different sizes.
- typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1];
+struct BitCastHelper {
+ STATIC_ASSERT(sizeof(Dest) == sizeof(Source));
- Dest dest;
- memcpy(&dest, &source, sizeof(dest));
- return dest;
-}
+ INLINE(static Dest cast(const Source& source)) {
+ Dest dest;
+ memcpy(&dest, &source, sizeof(dest));
+ return dest;
+ }
+};
template <class Dest, class Source>
-inline Dest BitCast(Source* source) {
- return BitCast<Dest>(reinterpret_cast<uintptr_t>(source));
+struct BitCastHelper<Dest, Source*> {
+ INLINE(static Dest cast(Source* source)) {
+ return BitCastHelper<Dest, uintptr_t>::
+ cast(reinterpret_cast<uintptr_t>(source));
+ }
+};
+
+template <class Dest, class Source>
+inline Dest BitCast(const Source& source) {
+ return BitCastHelper<Dest, Source>::cast(source);
}
} } // namespace v8::internal