]> gcc.gnu.org Git - gcc.git/commitdiff
ada: Better error message for bad general case statements
authorSteve Baird <baird@adacore.com>
Fri, 9 Feb 2024 23:08:51 +0000 (15:08 -0800)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 14 May 2024 08:19:54 +0000 (10:19 +0200)
If -gnatX0 is specified, we allow case statements with a selector
expression of a record or array type, but not of a private type.
If the selector expression is of a private type then we should generate
an appropriate error message instead of a bugbox.

gcc/ada/

* sem_ch5.adb (Analyze_Case_Statement): Emit a message and return
early in the case where general case statements are allowed but
the selector expression is of a private type. This is done to
avoid a bugbox.

gcc/ada/sem_ch5.adb

index 2677a2c5a1cc52cf5bdf4e74b7cdcf3ec225b020..65370ebfe7ea794166515feb8dfa458878706b35 100644 (file)
@@ -1497,6 +1497,15 @@ package body Sem_Ch5 is
          Resolve (Exp, Etype (Exp));
          Exp_Type := Etype (Exp);
          Is_General_Case_Statement := True;
+         if not (Is_Record_Type (Exp_Type) or Is_Array_Type (Exp_Type)) then
+            Error_Msg_N
+              ("selecting expression of general case statement " &
+               "must be a record or an array",
+               Exp);
+
+            --  Avoid cascading errors
+            return;
+         end if;
       else
          Analyze_And_Resolve (Exp, Any_Discrete);
          Exp_Type := Etype (Exp);
This page took 0.071792 seconds and 5 git commands to generate.