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

            Bug ID: 117569
           Summary: Predicate involving array indexing won’t compile in
                    generic
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: simon at pushface dot org
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

This code

pragma Extensions_Allowed (On);
generic
package Main is
   type Data is record
      X, Y : Positive;
      E    : Integer;
   end record;
   type ArrayInput is array (Positive range 1 .. <>) of Data with
     Dynamic_Predicate =>
      (for all I in 2 .. ArrayInput'Last =>
         ArrayInput (I).X < ArrayInput (I - 1).X or
         ArrayInput (I - 1).Y < ArrayInput (I).Y);
end Main;

fails with

GNAT 15.0.0 20241110 (experimental)
Copyright 1992-2024, Free Software Foundation, Inc.


Compiling: main.ads
Source file time stamp: 2024-11-12 16:53:01
Compiled at: 2024-11-13 17:27:33

     1. pragma Extensions_Allowed (On);
     2. generic
     3. package Main is
     4.    type Data is record
     5.       X, Y : Positive;
     6.       E    : Integer;
     7.    end record;
     8.    type ArrayInput is array (Positive range 1 .. <>) of Data with
     9.      Dynamic_Predicate =>
    10.       (for all I in 2 .. ArrayInput'Last =>
    11.          ArrayInput (I).X < ArrayInput (I - 1).X or
                 1                  2
        >>> error: reference to current instance of type does not denote a type
(RM 8.6)
        >>> error: reference to current instance of type does not denote a type
(RM 8.6)

    12.          ArrayInput (I - 1).Y < ArrayInput (I).Y);
                 1                      2
        >>> error: reference to current instance of type does not denote a type
(RM 8.6)
        >>> error: reference to current instance of type does not denote a type
(RM 8.6)

    13. end Main;

The code compiles without error if 'generic' is removed.

A simpler example fails similarly:

     1. generic
     2. package main2 is
     3.    type Data is record
     4.       X,Y: Positive;
     5.    end record;
     6.    type ArrayInput is array (Positive range <>) of Data with
     7.      Dynamic_Predicate =>
     8.       (for all I in ArrayInput'First + 1 .. ArrayInput'Last =>
     9.          ArrayInput (I).X < ArrayInput (I - 1).X or
                 1                  2
        >>> error: reference to current instance of type does not denote a type
(RM 8.6)
        >>> error: reference to current instance of type does not denote a type
(RM 8.6)

    10.          ArrayInput (I - 1).Y < ArrayInput (I).Y);
                 1                      2
        >>> error: reference to current instance of type does not denote a type
(RM 8.6)
        >>> error: reference to current instance of type does not denote a type
(RM 8.6)

    11. end main2;

With GCC 13 and 14 the compilation fails differently:

     7.      Dynamic_Predicate =>
     8.       (for all I in ArrayInput'First + 1 .. ArrayInput'Last =>
     9.          ArrayInput (I).X < ArrayInput (I - 1).X or
                               1                      2
        >>> error: invalid prefix in selected component "X"
        >>> error: invalid prefix in selected component "X"

    10.          ArrayInput (I - 1).Y < ArrayInput (I).Y);
                                   1                  2
        >>> error: invalid prefix in selected component "Y"
        >>> error: invalid prefix in selected component "Y"

    11. end main2;

Reply via email to