optimization - C++ optimizer removal of object with side effects -
this not problem, concerned if code gets ported or change compilers.
i have code block
{ myclass myobj; // copy other variables never touch myobj . . } // expect destructor called on myobj
where myobj never used in block code constructor has side effect , rely on destructor code of myclass executed @ close of block. works expected on current arm compiler optimization turned on.
my question is, there thing need do, declaring volatile or setting common attribute prevent optimizer detecting myobj unused variable or such.
this not c++11 compiler. said not problem did not want leave odd future bug else.
apart explicitly defined cases rvo (return value optimization), optimization not allowed change observable behaviour of program. optimizations must follow called "as-if" rule.
Comments
Post a Comment