I am attaching a small patch that works around issues with template function
overloading via auxiliary struct.
Both gcc 4.2 and gcc 4.4 compile this new code just fine.
Vlad can you try applying it to see if it helps in your case?
--
Vyacheslav Egorov
On Thu, Sep 2, 2010 at 9:52 AM, Vyacheslav Egorov <[email protected]>wrote:
> I think there is another solution: the rule of thumb for C++
> programmers it to avoid overloading of template functions because
> rules for choosing between two template candidates are extremely
> complicated.
>
> Instead programmers are encouraged to rely on partial template
> specialization which is available for classes/structs. So we can
> probably introduce auxiliary structure and rewrite the code in this
> way (it's just a blueprint):
>
> template<typename Dest, typename Source>
> class BitCastHelper {
> public:
> static Dest cast(const Source& src) { // generic bit cast };
> };
>
> template<typename Dest, typename Source>
> class BitCastHelper<Dest, Source*> {
> public:
> static Dest cast(const Source*& src) { // specialization for pointers };
> };
>
> template<typename Dest, typename Source>
> Dest BitCast(const Source& src) { return BitCastHelper<Dest,
> Source>::cast(src); }
>
> --
> Vyacheslav Egorov
>
>
> On Thu, Sep 2, 2010 at 8:57 AM, Søren Gjesse <[email protected]> wrote:
> >
> > Hi
> > This is a rather delicate matter and an area where we have been fighting
> with GCC and especially strict aliasing with GCC 4.4. You can follow it in
> issue 463. In r5237 we finally got a solution which fixed the GCC 4.4
> problem. This however caused problems with older GCCs which where addressed
> in r5305. However this last change seems to be the one which breaks
> compiling with RVCT. I just tried to re-introduce the & without the const,
> but that brings back the strict aliasing issue with GCC 4.4 (4.4.3).
> > Maybe the best solution here will be a conditional compile. Is there any
> predefined macros which can uniquily identify RVCT?
> > Regards,
> > Søren
> >
> > On Wed, Sep 1, 2010 at 19:04, vlad <[email protected]> wrote:
> >>
> >> Hi,
> >> Changing "Source* const & source" to just "Source* source" breaks rvct
> >> build... However Source*& source works fine.
> >>
> >> "v8.be\src\factory.h", line 335: Error: #308: more than one
> >> instance of overloaded function "v8::internal::BitCast" matches the ar
> >> gument list:
> >> function template
> >> "v8::internal::BitCast<Dest,Source>(const Source &)__softfp"
> >> function template
> >> "v8::internal::BitCast<Dest,Source>(Source *)__softfp"
> >> argument types are: (v8::internal::Object **)
> >> ROOT_LIST(ROOT_ACCESSOR)
> >>
> >> template <class Dest, class Source>
> >> inline Dest BitCast(Source* source) {
> >> return BitCast<Dest>(reinterpret_cast<uintptr_t>(source));
> >> }
> >>
> >> Thanks
> >> Vlad
> >>
> >> --
> >> 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
>
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-devdiff --git a/src/utils.h b/src/utils.h
index d605891..2dafa53 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -935,20 +935,32 @@ 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