On this page
B6007: 'Old of a value that owns access values
Catalog status: active. Default severity: error. Stable name: aliasing-old. Family: Ownership and finalization.
X'Old is a copy of X taken when the subprogram is entered. When X holds owning access values (an access-to-variable type, or a record or array with one inside), a plain copy would be a second owner of the same objects, which ownership forbids. So the prefix of 'Old must then be a call of a function, which makes a fresh value: a deep copy of the structure, or just the part the postcondition needs.
Example (Vada)
procedure Append (L : in out List; V : Integer)
with Post => (if L'Old /= null then L.Value = L'Old.Value);
-- L'Old would alias LExample (Varc)
fn append(l: inout List, v: Integer)
ensures if old(l) != null { l.value == old(l).value };
// old(l) would alias l
What to do (Vada)
Apply 'Old to a function of the value instead, such as one returning the scalar the postcondition compares:
function Head_Or (L : List; Default : Integer) return Integer is
(if L = null then Default else L.Value);
procedure Append (L : in out List; V : Integer)
with Post => L /= null and L.Value = Head_Or (L, V)'Old;What to do (Varc)
Apply old to a function of the value instead, such as one returning the scalar the postcondition compares:
fn head_or(l: List, default: Integer) -> Integer =
if l == null { default } else { l.value };
fn append(l: inout List, v: Integer)
ensures (l != null) & (l.value == old(head_or(l, v)));
Vada's and and Varc's & evaluate both sides. With and then or &&, this old function call would be in a part that might not be evaluated (B2015). The implementation must also establish the nonnull result needed to read the new head safely.
Regression source and further reading
Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.
See ownership and finalization, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.