lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re[2]: [lmi] Safe and consistent dereferencing and casting [Was: Code re


From: Vadim Zeitlin
Subject: Re[2]: [lmi] Safe and consistent dereferencing and casting [Was: Code review: product editor]
Date: Mon, 16 Apr 2007 20:54:21 +0200

On Mon, 16 Apr 2007 16:31:43 +0000 Greg Chicares <address@hidden> wrote:

GC> [5.2.9/5 == expr.static.cast p 5]
GC> | An lvalue of type "cv1 B" [...] can be cast to type "reference
GC> | to cv2 D", where D is a class derived [...] from B, if [snip
GC> | various requirements...] and B is not a virtual base class
GC> | of D.
GC> 
GC> The problem is that no one seems to know how to determine at
GC> compile time whether B is a virtual base,

 For the record, currently wxWidgets doesn't use virtual inheritance at all
and I hope this is not going to change in near future, so static_cast
should be safe to use.

GC> Regardless, is there any objection to adding this assertion:
GC> 
GC>  template<typename T, typename U>
GC>  T& safely_dereference_as(U* u)
GC>  {
GC> +    // Double parentheses: don't parse comma as a macro parameter 
separator.
GC> +    BOOST_STATIC_ASSERT
GC> +        ((
GC> +            boost::is_same            <U,T>::value
GC> +        ||  boost::is_base_and_derived<U,T>::value
GC> +        ));
GC> 
GC> along with the necessary boost headers?

 I think this is a good idea.

GC> Advantage: The generality given up isn't useful. Suppose we're
GC> dereferencing a wxControlWithItems* as a wxWindow&; then isn't
GC> our calling code mistakenly designed? I can't see a use case
GC> that we shouldn't forbid; if we discover one later, we can
GC> just remove the assertion.

 I can't see any useful cases in which this assert would fail neither,
thanks,
VZ





reply via email to

[Prev in Thread] Current Thread [Next in Thread]