@@ -222,6 +222,15 @@ private predicate addressMayEscapeMutablyAt(Expr e) {
222222 // If the address has been cast to an integral type, conservatively assume that it may eventually be cast back to a
223223 // pointer to non-const type.
224224 t instanceof IntegralType
225+ or
226+ // If we go through a temporary object step, we can take a reference to a temporary const pointer
227+ // object, where the pointer doesn't point to a const value
228+ exists ( TemporaryObjectExpr temp , PointerType pt |
229+ temp .getConversion ( ) = e .( ReferenceToExpr ) and
230+ pt = temp .getType ( ) .stripTopLevelSpecifiers ( )
231+ |
232+ not pt .getBaseType ( ) .isConst ( )
233+ )
225234 )
226235}
227236
@@ -249,7 +258,7 @@ private predicate addressFromVariableAccess(VariableAccess va, Expr e) {
249258 // `e` could be a pointer that is converted to a reference as the final step,
250259 // meaning that we pass a value that is two dereferences away from referring
251260 // to `va`. This happens, for example, with `void std::vector::push_back(T&&
252- // value);` when called as `v.push_back(&x)`, for a static variable `x`. It
261+ // value);` when called as `v.push_back(&x)`, for a variable `x`. It
253262 // can also happen when taking a reference to a const pointer to a
254263 // (potentially non-const) value.
255264 exists ( Expr pointerValue |
0 commit comments