Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2002-11-15 16:45:51

--- Douglas Gregor <gregod_at_[hidden]> wrote:
> On Friday 15 November 2002 03:36 pm, Gennaro Prota wrote:
> > of inventing a separate concept (say "Addressable") for them. The problem I
> > see in your resolution is that AFAIK addressof() is not guaranteed to work
> > by the standard. Yes, it has an extremely high probability to do the right
> > thing, but not a guarantee.
> You'll have to back that up with some standardese. AFAICT, 5.2.10/10 lets
> addressof() work:
> "That is, a reference cast reinterpret_cast<T&>(x) has the same effect as
> the conversion *reinterpret_cast<T*>(&x) with the builtin & and * operators."
> (And that reinterpret casting T* -> U* -> T* preserves the original value).

Yes, I do know that paragraph. I think it needs some modification if one wants
to make clear that the above is allowed. Basically when I read the standard I
take a conservative approach, i.e. if there's the slightest doubt that my
situation is not what the text guarantees to work I consider myself in an
undefined case. Now, let me say that there's an explicit contradiction (as
usual in such scenarios where a "special" case is assumed to be specified
separately) between 5.2.10/10 and 5.2.10/7, because the latter says that in


you can only cast back the result to the source type, whereas 5.2.10/10 defines
the reference-cast in terms of pointer-cast and says it's ok to *dereference*
the resulting value. However the real issue is that we have first

  T -> cv char& -> char &

and then

  char * -> T*

The latter is a reinterpret_cast from an rvalue of type char*, so except that I
can cast it back to a char* the result is unspecified. The problem exists
because the definitions are (correctly IMHO) given in terms of "expressions"
(lvalue/rvalue) not of objects, and thus from the perspective of the last cast
you "miss" the fact that actually you are dealing with the address of a T: the
expression has still type char*, no matter what the type of the object actually

In short, I agree with you that probably the intent is for it to work. But I
think that should be clarified.


Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site

Boost list run by bdawes at, gregod at, cpdaniel at, john at