You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @description Assigning a non-reference instance of a derived type to a variable of the base type slices off all members added by the derived class, and can cause an unexpected state.
* @kind problem
* @problem.severity warning
* @precision high
* @id cpp/slicing
* @tags quality
* reliability
* correctness
* types
*/
import cpp
fromAssignExpre,ClasslhsType,ClassrhsType
where
e.getLValue().getType()=lhsTypeand
e.getRValue().getType()=rhsTypeand
rhsType.getABaseClass+()=lhsTypeand
exists(Declarationm|
rhsType.getAMember()=mand
notm.(VirtualFunction).isPure()
)// add additional checks for concrete members in in-between supertypes
selecte,"This assignment expression slices from type $@ to $@.",rhsType,rhsType.getName(),