[PATCH] [exception] Replace C cast with reinterpret_cast for Metrowerks C++

Metrowerks C++ 2.4.1 thinks the type of (T*)0 is T, rather than T*. But reinterpret_cast works fine. --- This patch doesn't affect the compilation of g++ 4.0.1. diff --git boost/exception/exception.hpp boost/exception/exception.hpp index fd516dd..87063af 100644 --- boost/exception/exception.hpp +++ boost/exception/exception.hpp @@ -334,7 +334,7 @@ boost struct enable_error_info_return_type { - typedef typename enable_error_info_helper <T,sizeof(exception_detail::dispatch_boost_exception((T*)0))>::type type; + typedef typename enable_error_info_helper < T ,sizeof (exception_detail ::dispatch_boost_exception(reinterpret_cast<T*>(0)))>::type type; }; }

On 5 Mar 2011, at 09:48, Joshua Juran wrote:
Metrowerks C++ 2.4.1 thinks the type of (T*)0 is T, rather than T*. But reinterpret_cast works fine.
That is an incredibly strange bug. This also introduced a bug. (T*)0 is the expected way to get a null pointer of type T*. A reinterpret_cast is incorrect (although in practice likely to work on most machines / compiles) Does static_cast work? That would be fine instead of the C-style cast. Chris
---
This patch doesn't affect the compilation of g++ 4.0.1.
diff --git boost/exception/exception.hpp boost/exception/exception.hpp index fd516dd..87063af 100644 --- boost/exception/exception.hpp +++ boost/exception/exception.hpp @@ -334,7 +334,7 @@ boost struct enable_error_info_return_type { - typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch_boost_exception((T*)0))>::type type; + typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch_boost_exception(reinterpret_cast<T*>(0)))>::type type; }; }
<reinterpret_cast-for-MWC.patch>
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On Mar 5, 2011, at 2:07 AM, Christopher Jefferson wrote:
On 5 Mar 2011, at 09:48, Joshua Juran wrote:
Metrowerks C++ 2.4.1 thinks the type of (T*)0 is T, rather than T*. But reinterpret_cast works fine.
That is an incredibly strange bug.
Agreed.
This also introduced a bug. (T*)0 is the expected way to get a null pointer of type T*. A reinterpret_cast is incorrect (although in practice likely to work on most machines / compiles)
Does static_cast work? That would be fine instead of the C-style cast.
Yes, thanks for the correction. I'll resend the patch. Josh
participants (2)
-
Christopher Jefferson
-
Joshua Juran