3.6.3 Termination - statically

Help me understand this... see bold.
2 If a function contains a block-scope object of static or thread storage duration that has been destroyed and
the function is called during the destruction of an object with static or thread storage duration, the program has undefined behavior if the flow of control passes through the definition of the previously destroyed blockscope object. Likewise, the behavior is undefined if the block-scope object is used indirectly (i.e., through a
pointer) after its destruction.


The passes through the definition of the previously destroyed blockscope object has me puzzled.

1
2
3
4
5
Manager& GetManager()
{
    static Manager localMan;
    return localMa;
}


Then somewhere else...
1
2
3
4
{
   static User localUser;
   localUser.DoSomething(); //localUser calls GetManager and uses the reference returned.
}


Then in the User destructor...
1
2
3
4
User::~User()
{
   GetManager().DoSomethingOneLastTime();
}


1
2
3
4
//Now lets say Main exits and static destruction begins.
//Somehow localMan is destructed before User.
//Then user calls the GetManager() function in it's destructor.
//What case is this defined, and what case makes this undefined? 


Is the standard saying that if the local static localMan object that was statically created with the odr-use rule was destructed, and then the function was called again (creating a new static or not) this is undefined? It looks like it leaves room for there is defined behavior, but if it passes through the definition of the destructed object it is not.

Anyone have clear insight on this?
Last edited on
I think your understanding is correct.
Topic archived. No new replies allowed.