From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!8nKyDL3nVTTIdBB8axZhRA.user.46.165.242.75.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Generic formal ">" Date: Wed, 26 Jan 2022 16:54:50 +0000 Organization: Aioe.org NNTP Server Message-ID: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: gioia.aioe.org; logging-data="42893"; posting-host="8nKyDL3nVTTIdBB8axZhRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (darwin) X-Notice: Filtered by postfilter v. 0.9.2 Cancel-Lock: sha1:+P1ds/s1LpHTUa+osQ88zQFLzBk= Xref: reader02.eternal-september.org comp.lang.ada:63402 List-Id: I have a generic with a formal private type Element_Type and a formal function ">" (L, R : Element_Type) return Boolean. This gives me puzzling and compiler-dependent behaviour when I instantiate with ">" => "<". The output from the code below is GCC 10.1.0: Data'Length: 2 Data'Length > 1: TRUE Integer'(Data'Length) > 1: TRUE Standard.">" (Data'Length, 1): TRUE Standard.">" (Integer'(Data'Length), 1): TRUE GCC 11.1.0: Data'Length: 2 Data'Length > 1: FALSE Integer'(Data'Length) > 1: TRUE Standard.">" (Data'Length, 1): FALSE Standard.">" (Integer'(Data'Length), 1): TRUE I don't know what version of ">" will be used when the unqualified Data'Length is involved, but I would have expected that the overridden ("<") version would be used in the Integer'(Data'Length) version. (Sorry, I don't think overridden is the right word). GCC 10 uses the version from package standard even when given integer-qualified data. GCC 11 uses the version from package standard when given integer-qualified data, and the overriding version when not. Is it right that Standard.">" is getting overridden? Have the rules changed in this area? My "fix" was to compare Data'Length >= 2! 8X------------------- with Ada.Text_IO; use Ada.Text_IO; procedure Gen_Cmp is generic type Element_Type is private; type Index_Type is (<>); type Array_Type is array (Index_Type range <>) of Element_Type; with function ">" (Left, Right : Element_Type) return Boolean is <>; procedure Gen (Data: in out Array_Type); procedure Gen (Data: in out Array_Type) is begin Put_Line ("Data'Length:" & Data'Length'Image); Put_Line ("Data'Length > 1: " & Boolean'Image (Data'Length > 1)); Put_Line ("Integer'(Data'Length) > 1: " & Boolean'Image (Integer'(Data'Length) > 1)); Put_Line ("Standard."">"" (Data'Length, 1): " & Boolean'Image (Standard.">" (Data'Length, 1))); Put_Line ("Standard."">"" (Integer'(Data'Length), 1): " & Boolean'Image (Standard.">" (Integer'(Data'Length), 1))); end Gen; type Alpha is (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z); type My_Array is array (Alpha range <>) of Integer; procedure Chk_Down is new Gen (Element_Type => Integer, Index_Type => Alpha, Array_Type => My_Array, ">" => "<"); Data : My_Array (A .. B); begin Chk_Down (Data); end Gen_Cmp;