This patch fixes a crash on a case statement whose expression is an
attribute reference Type_Key, which yields a String. The attribute
reference may have been fully analyzed, and the resolution against
Any_Discrete fails to detect the error.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_attr.adb (Analyze_Attribute, case Type_Key): Attribute can
be applied to a formal type.
* sem_ch5.adb (Analyze_Case_Statement): If Extensions_Allowed is
not enabled, verify that the type of the expression is discrete.
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -6643,7 +6643,9 @@ package body Sem_Attr is
Initialize (CRC);
Compute_Type_Key (Entity (P));
- if not Is_Frozen (Entity (P)) then
+ if not Is_Frozen (Entity (P))
+ and then not Is_Generic_Type (Entity (P))
+ then
Error_Msg_N ("premature usage of Type_Key?", N);
end if;
diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -1681,6 +1681,13 @@ package body Sem_Ch5 is
Error_Msg_N
("(Ada 83) case expression cannot be of a generic type", Exp);
return;
+
+ elsif not Extensions_Allowed
+ and then not Is_Discrete_Type (Exp_Type)
+ then
+ Error_Msg_N
+ ("expression in case statement must be of a discrete_Type", Exp);
+ return;
end if;
-- If the case expression is a formal object of mode in out, then treat