RemoveAt in TList with duplicate

I think this is wrong. I want to swap the last element with the second:

o1 = ROOT.TNamed("o1", "o1")
o2 = ROOT.TNamed("o2", "o2")
o3 = ROOT.TNamed("o3", "o3")
l.Add(o1)
l.Add(o2)
l.Add(o3)
l.AddAfter(l.At(0), l.At(2))

now I have:

 OBJ: TNamed	o1	o1
 OBJ: TNamed	o3	o3
 OBJ: TNamed	o2	o2
 OBJ: TNamed	o3	o3
>>> l.RemoveAt(3)

but now I have:

 OBJ: TNamed	o1	o1
 OBJ: TNamed	o2	o2
 OBJ: TNamed	o3	o3

I Can see the same with the following macro. l.RemoveLast(); is ok but l.RemoveAt(3) is not …

{
   TList l;
   TNamed *o1 = new TNamed("o1", "o1");
   TNamed *o2 = new TNamed("o2", "o2");
   TNamed *o3 = new TNamed("o3", "o3");
   l.Add(o1);
   l.Add(o2);
   l.Add(o3);
   l.ls();
   l.AddAfter(o1,o3);
   l.ls();
   //l.RemoveAt(3); // Should be like RemoveLast() but is not.
   l.RemoveLast();
   l.ls();
}

I think I understand what’s is going on. RemoveAt() does:

TObject * RemoveAt(Int_t idx)
{ return Remove(At(idx)); }

At(idx) returns “o3”… then Remove() tries to Remove “o3”… and the 1st it found is at idx=1, and it removes this one. If you use o4 instead of o4 then it is ok:

OBJ: TList	TList	Doubly linked list : 0
 OBJ: TNamed	o1	o1 : 0 at: 0x7fe15c4dbea0
 OBJ: TNamed	o2	o2 : 0 at: 0x7fe15c4dcbf0
 OBJ: TNamed	o3	o3 : 0 at: 0x7fe15c4dcae0
OBJ: TList	TList	Doubly linked list : 0
 OBJ: TNamed	o1	o1 : 0 at: 0x7fe15c4dbea0
 OBJ: TNamed	o4	o4 : 0 at: 0x7fe15c4dcb90
 OBJ: TNamed	o2	o2 : 0 at: 0x7fe15c4dcbf0
 OBJ: TNamed	o3	o3 : 0 at: 0x7fe15c4dcae0
OBJ: TList	TList	Doubly linked list : 0
 OBJ: TNamed	o1	o1 : 0 at: 0x7fe15c4dbea0
 OBJ: TNamed	o4	o4 : 0 at: 0x7fe15c4dcb90
 OBJ: TNamed	o2	o2 : 0 at: 0x7fe15c4dcbf0

To do the swapping you should remove the object from the list before putting it in its new place.