In particular RM10.2.1(8) states:
5 An elaborable construct is preelaborable unless its elaboration
performs any of the following actions:
...
8 The evaluation of a primary that is a name of an object, unless
the name is a static expression, or statically denotes a
discriminant of an enclosing type.
which isn't enforced in the case of an object referenced in a range, as
in:
S : String (1 .. X);
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_cat.adb (Is_Primary): Handle N_Range properly.
diff --git a/gcc/ada/sem_cat.adb b/gcc/ada/sem_cat.adb
--- a/gcc/ada/sem_cat.adb
+++ b/gcc/ada/sem_cat.adb
@@ -2121,6 +2121,7 @@ package body Sem_Cat is
| N_Index_Or_Discriminant_Constraint
| N_Membership_Test
| N_Op
+ | N_Range
=>
return True;