> Can't I have sometihng like > > loop (i as iterator) > begin > I := F(0); > exception > when E => N := N + 1; > end; > > here I would expect PRE to discover I as loop invariant that will cause > exception to be called just once, not at every iteration of loop?
Yet the following testcase passes at -O2: -- { dg-do run } -- { dg-options "-O2" } with Opt35_Pkg; use Opt35_Pkg; procedure Opt36 is I : Integer := -1; N : Natural := 0; begin loop begin I := I + 1; I := I + F(0); exception when E => N := N +1; end; exit when I = 1; end loop; if N /= 2 or I = 0 then raise Program_Error; end if; end; > Can't the same happen for non-call exceptions? I don't think so, we don't have the equivalent of pure/const for non-call exceptions, in particular we have side effects. -- Eric Botcazou