tpaviot/oce — Issue #255: Returning reference to auto variable
Author: tpaviot
Created: 2012-02-11 20:25:03+00:00
State: open

I ran the latest cppcheck release, and it reports a few errors "Returing reference to auto variable".

For instance, at the line 485 of BOP_FaceBuilder.cxx:

//=======================================================================
//function : OldWire
//purpose :
//=======================================================================
const TopoDS_Shape& BOP_FaceBuilder::OldWire() const
{
const Handle(BOP_Loop)& L = myFaceAreaBuilder.Loop();
const TopoDS_Shape& B = L->Shape();
return B;
}

This function returns a reference to a local variable B which is destroyed when exiting the function. Don't know whether or not it is a false positive. Why not simply:

return L->Shape();

rather than creating this temporary variable?