1
帮我理解这一点...请参阅粗体。从标准3.6.3终止(2)本地静态物体的静态破坏
2如果函数包含静态或线程 存储持续时间的块范围对象已被破坏并且该功能的对象的与销毁过程中调用 静态或线程存储 持续时间,程序有未定义的行为,如果流量控制 通过先前销毁的块显示器 对象的定义。同样,如果块范围对象 在其销毁后间接使用(即通过指针),则行为未定义。
Manager& GetManager()
{
static Manager localMan;
return localMan;
}
然后别的地方...
{
static User localUser;
localUser.DoSomething(); //localUser calls GetManager and uses the reference returned.
}
在用户析构函数
则...
User::~User()
{
GetManager().DoSomethingOneLastTime();
}
//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?
是标准的话说,如果局部静态localMan对象是静态创建的odr-use规则被破坏,然后函数被再次调用(创建一个新的静态或不),这是未定义的?它看起来像是为定义的行为留下了空间,但是如果它通过了析构对象的定义,则不是。
任何人都对此有清晰的认识?