diff mbox

[Ada] Attributes on predicated subtypes

Message ID 20110804122104.GA2244@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Aug. 4, 2011, 12:21 p.m. UTC
To prevent anomalies with enumeration types with holes and scalar types with
complex predicates, the attributes First, Last, and Range cannot be applied to
subtypes with predicates. This rule applies only to scalar types.

The following must compile quietly in Ada2012 mode:

package Pred is
   type A is array (Integer range <>) of Integer
     with Predicate => (for all J in A'Range =>
                          (for all K in A'Range =>
                             (if J /= K then A (J) /= A (K))));
end Pred;

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-08-04  Ed Schonberg  <schonberg@adacore.com>

	* sem_attr.adb (Bad_Attribute_For_Predicate): flag illegal use of
	attribute only if prefix type is scalar.
diff mbox

Patch

Index: sem_attr.adb
===================================================================
--- sem_attr.adb	(revision 177351)
+++ sem_attr.adb	(working copy)
@@ -217,6 +217,8 @@ 
       --  actual, then the message is a warning, and we generate code to raise
       --  program error with an appropriate reason. No error message is given
       --  for internally generated uses of the attributes.
+      --  The legality rule only applies to scalar types, even though the
+      --  current AI mentions all subtypes.
 
       procedure Check_Array_Or_Scalar_Type;
       --  Common procedure used by First, Last, Range attribute to check
@@ -840,7 +842,9 @@ 
 
       procedure Bad_Attribute_For_Predicate is
       begin
-         if Comes_From_Source (N) then
+         if Is_Scalar_Type (P_Type)
+           and then  Comes_From_Source (N)
+         then
             Error_Msg_Name_1 := Aname;
             Bad_Predicated_Subtype_Use
               ("type& has predicates, attribute % not allowed", N, P_Type);