Say I have defined a variable like this (C++):
static const char str[] = "Here is some string data";
And I have a statically allocated class instance which references this array in its destructor, can this go wrong? E.g. could the str variable somehow get invalid?
class A {
~A() {
cout << str << endl;
}
};
static A a;
My assumption is that it can't go wrong, but I can find it clearly stated anywhere. I want to know this for sure. My assumption is that we can not predict the sequence in which destructors for statically allocated objects are called but that the data itself is never really freed until the process is torn down. Meaning pointers to POD should be safe, but not object instances.
Meaning e.g. this:
static const QString str = "Here is some string data";
or
static const std::string str = "Here is some string data";
Can not safely be used in A's destructor because they both allocate their string data on the heap and this might be freed by the destructor before A's destructor is called.
Is my assumption right and are there any sections in the C++ standard explaining this or some link to some other authority who can verify this?