@@ -19,30 +19,20 @@ import cpp
1919import codingstandards.cpp.autosar
2020import codingstandards.cpp.SmartPointers
2121
22- class AutosarSharedPointerOrDerived extends Type {
23- AutosarSharedPointerOrDerived ( ) {
24- this .getUnspecifiedType ( ) instanceof AutosarSharedPointer or
25- this .getUnspecifiedType ( ) .( DerivedType ) .getBaseType ( ) instanceof AutosarSharedPointer
26- }
27- }
28-
29- Expr underlyingObjectAffectingSharedPointerExpr ( Function f ) {
30- result =
31- any ( VariableAccess va , FunctionCall fc |
32- va .getEnclosingFunction ( ) = f and
33- // The type of the variable is either a shared_ptr, or a reference or pointer to a shared_ptr
34- va .getType ( ) instanceof AutosarSharedPointerOrDerived and
35- fc .getQualifier ( ) = va and
36- // include only calls to methods which modify the underlying object
37- fc .getTarget ( ) .hasName ( [ "operator=" , "reset" , "swap" ] )
38- |
39- va
40- )
22+ VariableAccess underlyingObjectAffectingSharedPointerExpr ( Function f ) {
23+ exists ( FunctionCall fc |
24+ // Find a call in the function
25+ fc .getEnclosingFunction ( ) = f and
26+ // include only calls to methods which modify the underlying object
27+ fc = any ( AutosarSharedPointer s ) .getAModifyingCall ( ) and
28+ // Report the qualifier
29+ fc .getQualifier ( ) = result
30+ )
4131}
4232
4333predicate flowsToUnderlyingObjectAffectingExpr ( Parameter p ) {
4434// check if a parameter flows locally to an expression which affects smart pointer lifetime
45- p .getType ( ) instanceof AutosarSharedPointerOrDerived and
35+ p .getType ( ) . stripType ( ) instanceof AutosarSharedPointer and
4636localExprFlow ( p .getAnAccess ( ) , underlyingObjectAffectingSharedPointerExpr ( p .getFunction ( ) ) )
4737or
4838// else handle nested cases, such as passing smart pointers as reference arguments
@@ -60,7 +50,7 @@ predicate flowsToUnderlyingObjectAffectingExpr(Parameter p) {
6050from DefinedSmartPointerParameter p , string problem
6151where
6252not isExcluded ( p , SmartPointers1Package:: smartPointerAsParameterWithoutLifetimeSemanticsQuery ( ) ) and
63- p .getType ( ) instanceof AutosarSharedPointerOrDerived and
53+ p .getType ( ) . stripType ( ) instanceof AutosarSharedPointer and
6454(
6555// handle the parameter depending on its derived type
6656p .getType ( ) instanceof RValueReferenceType and