Boost logo

Boost Users :

Subject: Re: [Boost-users] [Review] Formal Review: Boost.Move
From: Neil Groves (neil_at_[hidden])
Date: 2010-05-23 05:15:13


>
>
> There's no conversion through void* but gcc still crashes with static_cast.
> C++ aliasing rules allow accesing a type T by through a base class, but
> we're accessing it through a non-existing derived type (rv<T>) so, I think
> this breaks aliasing rules. Adding __attribute__((__may_alias__)) to rv to
> tell the compiler that rv could alias any type seems to fix the problem
> (although is overkill IMHO). See:
>
>
> https://svn.boost.org/trac/boost/ticket/3950
>
>
Sadly while it fixes the problems in unit test. I have an application where
I did added the may_alias attribute, and now I get passed unit tests for
move and compiler defects in function lookup for classes that use
RVALUE_REF. This isn't a complete fix for GCC 4.4. I'm still working on a
better solution, and a proper review.

I convinced myself that with static_casts do not break strict aliasing rules
since the conversion from rv<T>* to T* is valid. I believe that section
5.2.9 para 2 applies:

"An lvalue of type “cv1 B,” where B is a class type, can be cast to type
“reference to cv2 D,” where D is a class
derived (Clause 10) from B, if a valid standard conversion from “pointer to
D” to “pointer to B” exists (4.10),
cv2 is the same cv-qualification as, or greater cv-qualification than, cv1,
and B is neither a virtual base class
of D nor a base class of a virtual base class of D. The result has type “cv2
D.” An rvalue of type “cv1 B” may
be cast to type “rvalue reference to cv2 D” with the same constraints as for
an lvalue of type “cv1 B.” If the
object of type “cv1 B” is actually a subobject of an object of type D, the
result refers to the enclosing object
of type D. Otherwise, the result of the cast is undefined."

I'll get back to you after a little more experimentation.

Regards,
Neil Groves



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net