Can someone test this short code (compiler error?)

Could someone test this code:

with Ada.Text_IO; use Ada.Text_IO;
procedure test1 is

  type fam_rel1_t is (f_c, f_d1, f_d2, f_d3, f_d4, f_d5, f_d6);
  for fam_rel1_t use (f_c=>1, f_d1=>2, f_d2=>3, f_d3=>4, f_d4=>5, f_d5=>6, f_d6=>7);

begin

   for d in fam_rel1_t loop
       if d /= f_c then
          put_line("Here 1: " & d'Image);
       end if;
   end loop;

   Put_Line("============================");

   for d in fam_rel1_t when d /= f_c loop
       put_line("Here 2: " & d'Image);
   end loop;

end test1;

I get this output when I include “for .. use”:
Here 1: F_D1
Here 1: F_D2
Here 1: F_D3
Here 1: F_D4
Here 1: F_D5
Here 1: F_D6

=====================================

Here 2: F_C
Here 2: F_D1
Here 2: F_D2
Here 2: F_D3
Here 2: F_D4
Here 2: F_D5
Here 2: F_D6

I use latest version of debian and alire.

Here you go: Compiler Explorer
(I changed the procedure name to example because of some Godbolt peculiarities)

Edit:
a sounder example: Compiler Explorer

I changed the compiler to truck and it does the same! Wierd! Mmmmm… This looks like a compiler bug… I think this should be reported to upstream.

Same result on Arch gcc version 15.2.1 20260103.

I’ve never seen a ‘when’ in a ‘for’ loop like that before. Is it a new 2022 addition ?

I made an illegal construct (without getting an error message) ?

Note that “for .. use” has an effect. Try to comment it out (or remove it).

Yup! It is new syntax :slight_smile:

Afaik, it is only a representation clause, so it should not affect the logic…

Has already been reported some time ago:

1 Like