]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Error on subtype with static predicate used in case_expression
authorGary Dismukes <dismukes@adacore.com>
Sat, 22 Mar 2025 00:01:52 +0000 (00:01 +0000)
committerEric Botcazou <ebotcazou@adacore.com>
Tue, 10 Jun 2025 09:00:12 +0000 (11:00 +0200)
The compiler improperly flags an error on the use of a subtype with a
static predicate as a choice in a case expression alternative, complaining
that the subtype has a nonstatic predicate. The fix for this is to add
a test for the subtype not having a static predicate.

gcc/ada/ChangeLog:

* einfo.ads: Revise comment about Dynamic_Predicate flag to make it
more accurate.
* sem_case.adb (Check_Choices): Test "not Has_Static_Predicate_Aspect"
as additional guard for error about use of subtype with nonstatic
predicate as a case choice. Improve related error message.

gcc/ada/einfo.ads
gcc/ada/sem_case.adb

index f154e7f0d763a1d201dc48a12f00abf08ff8b080..7c05e532aea7a83ed82c2ec8eb446b19652e0c6d 100644 (file)
@@ -1623,7 +1623,7 @@ package Einfo is
 
 --    Has_Dynamic_Predicate_Aspect
 --       Defined in all types and subtypes. Set if a Dynamic_Predicate aspect
---       was explicitly applied to the type. Generally we treat predicates as
+--       was applied to the type or subtype. Generally we treat predicates as
 --       static if possible, regardless of whether they are specified using
 --       Predicate, Static_Predicate, or Dynamic_Predicate. And if a predicate
 --       can be treated as static (i.e. its expression is predicate-static),
index 3399a41343e8a480bc750a15855ea3bb488b1a78..c81b56337f6a6b92d586c632d6d08c60b8b1f17a 100644 (file)
@@ -3684,13 +3684,15 @@ package body Sem_Case is
                            --  Use of nonstatic predicate is an error
 
                            if not Is_Discrete_Type (E)
-                             or else not Has_Static_Predicate (E)
+                             or else (not Has_Static_Predicate (E)
+                                        and then
+                                      not Has_Static_Predicate_Aspect (E))
                              or else Has_Dynamic_Predicate_Aspect (E)
                              or else Has_Ghost_Predicate_Aspect (E)
                            then
                               Bad_Predicated_Subtype_Use
-                                ("cannot use subtype& with non-static "
-                                 & "predicate as case alternative",
+                                ("cannot use subtype& with nonstatic "
+                                 & "predicate as choice in case alternative",
                                  Choice, E, Suggest_Static => True);
 
                            --  Static predicate case. The bounds are those of