• Generic formal ">"

    From Simon Wright@21:1/5 to All on Wed Jan 26 16:54:50 2022
    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;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From AdaMagica@21:1/5 to All on Wed Jan 26 10:48:56 2022
    Within the generic, data'length is an integer value of type universal integer. This has nothing to do with the generic parameter Element_Type, even if this is instantiated with Integer.
    The predefined attribute 'Image produces a string from parameter Integer. So Data'Length is implicitly converted from universal_integer to integer. This is independent from the generic parameter Element_Type.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeffrey R.Carter@21:1/5 to Simon Wright on Wed Jan 26 19:46:06 2022
    On 2022-01-26 17:54, Simon Wright wrote:

    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

    This looks like an error introduced in V11. 'Length is universal_integer, which has no primitive subprograms. Within the generic, Element_Type and Integer are distinct types, and Element_Type is not a numeric type. So Data'Length should not be converted to Element_Type, and the ">" defined for Element_Type should not be invoked. This is also true for Integer'(Data'Length).

    --
    Jeff Carter
    "Son of a window-dresser."
    Monty Python & the Holy Grail
    12

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From AdaMagica@21:1/5 to All on Wed Jan 26 11:00:22 2022
    GNAT CE 2021 produces the wrong result. You should definitely report this.

    Data'Length: 2
    Data'Length > 1: FALSE
    Integer'(Data'Length) > 1: TRUE
    Standard.">" (Data'Length, 1): FALSE
    Standard.">" (Integer'(Data'Length), 1): TRUE
    [2022-01-26 19:53:10] process terminated successfully, elapsed time: 02.39s

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Simon Wright@21:1/5 to AdaMagica on Thu Jan 27 12:05:35 2022
    AdaMagica <christ-usch.grein@t-online.de> writes:

    GNAT CE 2021 produces the wrong result. You should definitely report this.

    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104258

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)