Boost logo

Boost :

From: Steven Watanabe (steven_at_[hidden])
Date: 2007-10-11 20:23:42


Simonson, Lucanus J <lucanus.j.simonson <at>> writes:

> The reason it is categorized as undefined is because Derived may extend
> Base by adding data members, inheriting from another base, or adding a
> virtual pointer.

Here are some other things which could break your code:

// this is POD
struct Base {
    char c;

// This is not POD
struct Derived : Base {
    int hidden_variable_added_by_the_compiler;

Now the alignment of Derived is stricter than that of Base.
The standard explicitly states that using a reinterpret_cast
from Base to Derived is not guaranteed to be reversible.
It also states that the result of a static_cast from Base to
Derived is unspecified.

Another example

// This is POD
struct Base {

class Derived {
    thread_id_t hidden_variable_added_by_compiler;
    void f() {
        // code added by compiler
        // Try to determine whether the class Derived
        // may need to be thread safe. Note that more
        // sophisticated tests are possible, such as checking
        // whether some mutex is locked.
        if(hidden_variable_added_by_compiler != get_current_thread_id()) {
            if(hidden_variable_added_by_compiler == 0) {
                hidden_variable_added_by_compiler = get_current_thread_id();
            } else {

        //use Base only

Now even though f doesn't appear to access any derived class members
it really does.

In Christ,
Steven Watanabe

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