From: Julien Bortolussi Date: Thu, 4 Aug 2022 16:15:13 +0000 (+0200) Subject: [Ada] Fix a bug in the contract of formal ordered sets X-Git-Tag: basepoints/gcc-14~4739 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eae9f5d25713013a6fa3e6c60f7f744ab3bf778b;p=thirdparty%2Fgcc.git [Ada] Fix a bug in the contract of formal ordered sets There are 2 main issues in the postcondition of the function Replace of the formal ordered sets, in the sub package Generic_Keys. One is related to the fact that when the element is changed, the key is also changed. The second one is due to the fact that the arrival of the new element might modify the ordering of the set and thus the Positions might be modified. As a consequence, the postcondition might be false and thus fail at runtime. gcc/ada/ * libgnat/a-cforse.ads (Replace): Fix the postcondition. --- diff --git a/gcc/ada/libgnat/a-cforse.ads b/gcc/ada/libgnat/a-cforse.ads index ff96d8e7547b..f6cca0fe0528 100644 --- a/gcc/ada/libgnat/a-cforse.ads +++ b/gcc/ada/libgnat/a-cforse.ads @@ -1598,7 +1598,7 @@ is -- Key now maps to New_Item - and Element (Container, Key) = New_Item + and Element (Container, Find (Container, Key)'Old) = New_Item -- New_Item is contained in Container @@ -1622,8 +1622,9 @@ is E_Right => Elements (Container), P_Left => Positions (Container)'Old, P_Right => Positions (Container), - Position => Find (Container, Key)) - and Positions (Container) = Positions (Container)'Old; + Position => Find (Container, Key)'Old) + and P.Keys_Included (Positions (Container), + Positions (Container)'Old); procedure Exclude (Container : in out Set; Key : Key_Type) with Global => null,