Boost logo

Boost :

Subject: Re: [boost] [local_function] how bad is this `static_cast<>`?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-09-09 12:13:03


AMDG

Lorenzo Caminiti wrote:
> How bad is the `static_cast<>` below?
>
> struct c {
> void g() {}
>
> void f() {
> struct l: c { // Local function class wrapper.
> void body() {
> g(); // Usual implicit `this` access.
> this->g(); // Usual explicit `this` access.
> }
> };
>
> static_cast<l*>(this)->body(); // *** HOW BAD IS THIS
> `STATIC_CAST<>`? ***
> }
> };
>
> Could Boost.LocalFunction internally use such a technique when a
> special configuration macro is #defined by the users?
>
> IMO, if this `static_cast<>` can really corrupt memory on some
> systems/compilers, maybe Boost.LocalFunction should *never* use it.
> Otherwise, what would the documentation say "WARNING: If you #define
> this configuration macro, memory could be corrupted in some unknown
> way on some unknown combination of systems/compilers..." -- it's like
> providing a self-destruction button with a random countdown sequence
> via the configuration macro! What do you think?
>

The problem with code like this is that it can cause the optimizer
to make incorrect assumptions and miscompile the code. I
believe that this has been observed with gcc.

In Christ,
Steven Watanabe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk