Open amelvill-umich opened 4 years ago
It depends on how you want to read the documentation,
Note that rvalue references and lvalue references to const extend the lifetimes of temporary objects (see Reference initialization for rules and exceptions).
Re-reading that again, the exceptions are,
a temporary bound to a return value of a function in a return statement is not extended: it is destroyed immediately at the end of the return expression. Such function always returns a dangling reference.
So a const ref would extend the lifetime of the temporary, if not for the fact that the temporary is taking a ref to a return value.
I'm going to say this is UB.
This issue is still present in MITK's master branch.
Reported to MITK mailing list 10/20/2020
This call to
GetControlPoint
stores the return value in a referencehttps://github.com/carthurs/MITK/blob/4e084d2d790cac945757ead66b2898ca70e5cd28/Modules/PlanarFigure/src/DataManagement/mitkPlanarEllipse.cpp#L68
But
GetControlPoint
does not return aPoint2D&
, it returns aPoint2D
https://github.com/carthurs/MITK/blob/4e084d2d790cac945757ead66b2898ca70e5cd28/Modules/PlanarFigure/src/DataManagement/mitkPlanarFigure.cpp#L253
I am pretty sure that this a typo on MITK's part.
From "Lifetime of a temporary" https://en.cppreference.com/w/cpp/language/reference_initialization
I would take that to mean that the true lifetime of
centerPoint
is a single line.https://github.com/carthurs/MITK/blob/4e084d2d790cac945757ead66b2898ca70e5cd28/Modules/PlanarFigure/src/DataManagement/mitkPlanarEllipse.cpp#L68-L107
There is an exception for const references,:
Bottom of: https://en.cppreference.com/w/cpp/language/reference#Lvalue_references
Even if they did, in theory MITK should work on Linux, Mac, and Windows, so this may be platform specific behavior.