• Safe to ignore warnings about function mistaken as primitive?

    From G.B.@21:1/5 to All on Sun Jul 10 10:45:24 2022
    GNAT warns about primitive operations appearing too late in the text.
    In the following example, though, F is not meant to be a primitive
    operation of A.Some_Tagged, but instead one of type B.Plain.

    Can I ignore the warning?


    gcc -gnatl -c rt_warn.ads

    GNAT 11.2.0
    Copyright 1992-2021, Free Software Foundation, Inc.
    cannot generate code for file rt_warn.ads (package spec)


    Compiling: rt_warn.ads
    Source file time stamp: 2022-07-10 08:34:32
    Compiled at: 2022-07-10 10:34:39

    1. package Rt_Warn is
    2.
    3. package A is
    4.
    5. type Some_Tagged is interface;
    6.
    7. end A;
    8.
    9. package B is
    10.
    11. type Plain is private;
    12.
    13. function F (Param : A.Some_Tagged) return Plain;
    |
    >>> warning: declaration of "F" is too late
    >>> warning: spec should appear immediately after declaration of "Some_Tagged"

    14. function FC (Param : A.Some_Tagged'Class) return Plain;
    15. private
    16. type Plain is record
    17. null;
    18. end record;
    19. end B;
    20.
    21. end Rt_Warn;

    21 lines: No errors, 2 warnings

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to G.B. on Sun Jul 10 12:19:11 2022
    On 2022-07-10 10:45, G.B. wrote:
    GNAT warns about primitive operations appearing too late in the text.
    In the following example, though, F is not meant to be a primitive
    operation of A.Some_Tagged, but instead one of type B.Plain.

    Can I ignore the warning?

    gcc -gnatl -c rt_warn.ads

    GNAT 11.2.0
    Copyright 1992-2021, Free Software Foundation, Inc.
    cannot generate code for file rt_warn.ads (package spec)


    Compiling: rt_warn.ads
    Source file time stamp: 2022-07-10 08:34:32
    Compiled at: 2022-07-10 10:34:39

         1. package Rt_Warn is
         2.
         3.     package A is
         4.
         5.         type Some_Tagged is interface;
         6.
         7.     end A;
         8.
         9.     package B is
        10.
        11.         type Plain is private;
        12.
        13.         function F (Param : A.Some_Tagged) return Plain;
                             |
            >>> warning: declaration of "F" is too late
            >>> warning: spec should appear immediately after declaration of "Some_Tagged"

    Some_Tagged is an interface, it cannot have implementations anyway.
    Should be an error rather than just warning to me.

    --
    Regards,
    Dmitry A. Kazakov
    http://www.dmitry-kazakov.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stephen Leake@21:1/5 to G.B. on Sun Jul 10 21:27:16 2022
    "G.B." <bauhaus@notmyhomepage.invalid> writes:

    GNAT warns about primitive operations appearing too late in the text.
    In the following example, though, F is not meant to be a primitive
    operation of A.Some_Tagged, but instead one of type B.Plain.

    Can I ignore the warning?

    It's best to never ignore warnings, but instead fix them. Even if the
    only way to "fix" it is to add "pragma Warnings (Off ...)"; that at
    least tells the reader you have considered the warning.

    Since B.F is declared in a sibling package, it cannot a primitive of A.Some_Tagged, so the error message is wrong.

    Since A.Some_Tagged is an interface, you can only declare abstract
    primitive subprograms for it. So I suspect GNAT knows there's an error, but is giving a confusing error message.

    How are you intending F to be different from FC?

    --
    -- Stephe

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From G.B.@21:1/5 to Stephen Leake on Mon Jul 11 15:17:44 2022
    On 11.07.22 06:27, Stephen Leake wrote:

    Since B.F is declared in a sibling package, it cannot a primitive of A.Some_Tagged, so the error message is wrong.

    Since A.Some_Tagged is an interface, you can only declare abstract
    primitive subprograms for it. So I suspect GNAT knows there's an error, but is
    giving a confusing error message.

    It seems possible to write programs declaring B.F (Param : A.Some_Tagged)..., but hardly one that isn't pointless! Adding "in out" to the
    function's Param allows 'Access using 'Class renames Ref'(Param'Access).all
    and then 'Unchecked_Access---so twisted I shan't repeat it here.
    Adding (... : access A.Some_Tagged) works a lot better (of course <:-|),
    and still has the warning.

    But, GNAT is right, I think!

    How are you intending F to be different from FC?

    The first F was a bad choice, I guess; I had wanted to exclude a potentially larger interface. FC was the beginning of dropping F.
    FC now takes an access to class-wide.

    With Op1 added to the interface of Some_Tagged,

    package B is
    type Plain(<>) is private;

    function FC (Param : access A.Some_Tagged'Class) return Plain;
    procedure G (Item : in out Plain; Param : in Character);
    -- Calls Op1 of Item.Client
    private
    type Plain (Client : access A.Some_Tagged'Class) is record
    null;
    end record;
    end B;

    No F, no warning.

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