1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0026377: Passing Handle objects as arguments to functions as non-const reference to base type is dangerous

Operator of cast to non-const reference is declared deprecated to produce compiler warning if used (usually implicitly).

OCCT code is updated to avoid that cast, occurring when function accepting non-const reference to handle is called with handle to derived type.
For that, local variable of argument type is passed instead, and down-cast is used to get it to desired type after the call.
A few occurrences of use of uninitialized variable are corrected.
This commit is contained in:
abv
2016-02-17 17:33:18 +03:00
parent fe9b8ff2f2
commit aa00364da7
59 changed files with 395 additions and 211 deletions

View File

@@ -185,6 +185,14 @@ public:
//! this method.
Standard_EXPORT Standard_Boolean FindAttribute (const Standard_GUID& anID, Handle(TDF_Attribute)& anAttribute) const;
//! Safe variant for arbitrary type of argument
template <class T>
Standard_Boolean FindAttribute (const Standard_GUID& theID, Handle(T)& theAttr) const
{
Handle(TDF_Attribute) anAttr = theAttr;
return FindAttribute (theID, anAttr) && ! (theAttr = Handle(T)::DownCast(anAttr)).IsNull();
}
//! Adds an Attribute <other> to the label of
//! <me>.Raises if there is already one of the same
//! GUID fhan <other>.

View File

@@ -150,6 +150,14 @@ public:
//! A removed attribute cannot be found.
Standard_EXPORT Standard_Boolean FindAttribute (const Standard_GUID& anID, Handle(TDF_Attribute)& anAttribute) const;
//! Safe variant of FindAttribute() for arbitrary type of argument
template <class T>
Standard_Boolean FindAttribute (const Standard_GUID& theID, Handle(T)& theAttr) const
{
Handle(TDF_Attribute) anAttr = theAttr;
return FindAttribute (theID, anAttr) && ! (theAttr = Handle(T)::DownCast(anAttr)).IsNull();
}
//! Finds an attribute of the current label, according
//! to <anID> and <aTransaction>. This attribute
//! has/had to be a valid one for the given

View File

@@ -106,6 +106,14 @@ public:
//! explanation about the method behavior)
Standard_EXPORT Standard_Boolean HasRelocation (const Handle(TDF_Attribute)& aSourceAttribute, Handle(TDF_Attribute)& aTargetAttribute) const;
//! Safe variant for arbitrary type of argument
template <class T>
Standard_Boolean HasRelocation (const Handle(TDF_Attribute)& theSource, Handle(T)& theTarget) const
{
Handle(TDF_Attribute) anAttr = theTarget;
return HasRelocation (theSource, anAttr) && ! (theTarget = Handle(T)::DownCast(anAttr)).IsNull();
}
//! Sets the relocation value of <aSourceTransient> to
//! <aTargetTransient>.
Standard_EXPORT void SetTransientRelocation (const Handle(Standard_Transient)& aSourceTransient, const Handle(Standard_Transient)& aTargetTransient);