Hello,

How many people know about return value optimization? Its a very good thing to 
know about! Here a wiki page to know what it's about:

http://en.wikipedia.org/wiki/Return_value_optimization


The relevant part for this discussion: "an implementation may omit a copy 
operation resulting from a return statement, even if the copy constructor has 
side effects".

It appears that all the compiler still aggressively use return value 
optimization in debug mode except Visual Studio. It's calling the copy 
constructor when the is a local, and the tests are failing due to the 
side-effect occurring.


So The VectorImage::GetPixel method constructs a VariableLengthVector which 
doesn't owns the memory, but references and returns it:

https://github.com/Kitware/ITK/blob/master/Modules/Core/Common/include/itkVectorImage.h#L244

Then in the tests we are setting this returned value assuming it will modify 
the data in the actual Image:

https://github.com/Kitware/ITK/blob/master/Modules/Core/ImageFunction/test/itkLinearInterpolateImageFunctionTest.cxx#L146

It will do the modification if return value optimization has occurred. But if a 
copy constructor is called as it is with Visual Studio, then a deep copy of the 
VariableLengthVector will have occurred do the image will not get modified.

I thought this was a very interesting bug. And that sharing it may make more 
developers aware of this potential issue was writing VectorImage and 
VariableLengthVector code.

Here is the patch which should fix the outstanding Interpolator failing tests 
with Visual Studio debug:

http://review.source.kitware.com/#/c/11456/

Brad 
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-developers

Reply via email to