TopoDS_Shape is rewritten at an unintended time

Hello. When the following code is executed and an exception occurs, the argument TopoDS_Shape is rewritten.

Why is the value of shape rewritten in CodeA and CodeB?

[CodeA]

// shape is valid ( checked by BRepCheck_Analyzer::IsValid() )
TopoDS_Shape shapeBuf = shape;
testA( shapeBuf );
// shape is invalid.

testA( TopoDS_Shape shape ) {
  try {
    ShapeUpgrade_UnifySameDomain unif( shape, Standard_True, Standard_True, Standard_True );
    unif.Build();
  } catch ( const Standard_Failure& theFailure ) {
    // exception StdFail_NotDone : BRep_API: command not done
  }
}

[CodeB]

// shape is valid ( checked by BRepCheck_Analyzer::IsValid() )
TopoDS_Shape shapeBuf = shape;
testB( shapeBuf );
// shape is invalid.

testB( const TopoDS_Shape &shape ) {
  try {
    ShapeUpgrade_UnifySameDomain unif( shape, Standard_True, Standard_True, Standard_True );
    unif.Build();
  } catch ( const Standard_Failure& theFailure ) {
    // exception StdFail_NotDone : BRep_API: command not done
  }
}

And why is the value of shape not rewritten in CodeC?

[CodeC]

BRepBuilderAPI_Copy A;
A.Perform( shape );
TopoDS_Shape shapeBuf = A.Shape();
// shape is valid ( checked by BRepCheck_Analyzer::IsValid() )
testA( shape );
// shape is valid.

[Environment]

Opencascade: V7.5.3
OS: Windows 10 Pro 64bit
CPU: Intel(R) Core(TM) i7-8550U
Memory: 16GB

Best Regards.

Attachments: 
Eugene Zaliznyak's picture

Yes, it looks also strange for me.
ShapeUpgrade_UnifySameDomain takes argument as const TopoDS_Shape&, and logically (even TopoDS_Shape is only container constant) input geometry cannot be editable. I saw the same strange thing in another algorithm also.