mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +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:
@@ -240,6 +240,14 @@ public:
|
||||
//! immediately used, well initialised
|
||||
Standard_EXPORT Standard_Boolean FindTypedTransient (const Handle(Transfer_Finder)& start, const Handle(Standard_Type)& atype, Handle(Standard_Transient)& val) const;
|
||||
|
||||
//! Safe variant for arbitrary type of argument
|
||||
template <class T>
|
||||
Standard_Boolean FindTypedTransient (const Handle(Transfer_Finder)& start, const Handle(Standard_Type)& atype, Handle(T)& val) const
|
||||
{
|
||||
Handle(Standard_Transient) aVal = val;
|
||||
return FindTypedTransient (start, atype, aVal) && ! (val = Handle(T)::DownCast(aVal)).IsNull();
|
||||
}
|
||||
|
||||
//! Searches for a transient result recorded in a Binder, whatever
|
||||
//! this Binder is recorded or not in <me>
|
||||
//!
|
||||
@@ -249,6 +257,14 @@ public:
|
||||
//! Apart from this, works as FindTypedTransient
|
||||
Standard_EXPORT Standard_Boolean GetTypedTransient (const Handle(Transfer_Binder)& binder, const Handle(Standard_Type)& atype, Handle(Standard_Transient)& val) const;
|
||||
|
||||
//! Safe variant for arbitrary type of argument
|
||||
template <class T>
|
||||
Standard_Boolean GetTypedTransient (const Handle(Transfer_Binder)& start, const Handle(Standard_Type)& atype, Handle(T)& val) const
|
||||
{
|
||||
Handle(Standard_Transient) aVal = val;
|
||||
return GetTypedTransient (start, atype, aVal) && ! (val = Handle(T)::DownCast(aVal)).IsNull();
|
||||
}
|
||||
|
||||
//! Returns the maximum possible value for Map Index
|
||||
//! (no result can be bound with a value greater than it)
|
||||
Standard_EXPORT Standard_Integer NbMapped() const;
|
||||
|
Reference in New Issue
Block a user