On this page
B6002: use of a moved value
Catalog status: active. Default severity: error. Stable name: use-after-move. Family: Ownership and finalization.
A value of a pool-specific access type owns the object it designates, so assigning it to another object (or passing it to an out parameter) moves it: the new object owns the designated object, and the old one may no longer be used, because two owners could free the same object or change it behind each other's backs. This applies to every part of an object that holds access values, and to an object whose part was moved. A move is undone by assigning the moved object a new value.
Example (Vada)
type Cell is access Integer;
A : Cell := new Integer'(1);
B : Cell;
X : Integer;
begin
B := A; -- A's object now belongs to B
X := A.all; -- A no longer designates anything it ownsExample (Varc)
type Cell = *Integer;
var a: Cell = new Integer(1);
var b: Cell;
var x: Integer;
...
b = a; // a's object now belongs to b
x = *a; // a no longer designates anything it owns
What to do (Vada)
Read the object through its new owner (B.all), or give the old one a new value first (A := new Integer'(2);, or move the value back: A := B;).
What to do (Varc)
Read the object through its new owner (*b), or give the old one a new value first (a = new Integer(2);, or move the value back: a = b;).
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.