public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Spurious error on container instantiation with predicated array type
@ 2016-07-06 12:38 Arnaud Charlet
  0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2016-07-06 12:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ed Schonberg

[-- Attachment #1: Type: text/plain, Size: 1752 bytes --]

This patch fixes a spurious type error in a predicate function created within
an operation in an instantiation of a container package, when the element
type is an unconstrained array with a predicate.

The following must compile quietly 

   gcc -c gpr2-project-registry-attribute.adb

---
with Ada.Containers.Indefinite_Ordered_Maps; use Ada;
with Ada.Strings.Less_Case_Insensitive;

package body GPR2.Project.Registry.Attribute is

   function Less_Case_Insensitive
     (Left, Right : Qualified_Name) return Boolean is
     (Ada.Strings.Less_Case_Insensitive (String (Left), String (Right)));

   package Attribute_Definitions is new Containers.Indefinite_Ordered_Maps
     (Qualified_Name, Def, Less_Case_Insensitive);

end GPR2.Project.Registry.Attribute;

package GPR2.Project.Registry.Attribute is

   pragma Elaborate_Body;

   type Index_Kind is (No, Yes, Optional);

   type Qualified_Name is new Name_Type;

   type Def is record
      Index : Index_Kind;
   end record;

end GPR2.Project.Registry.Attribute;
package GPR2.Project.Registry is
end GPR2.Project.Registry;
package GPR2.Project is

end GPR2.Project;
package GPR2 is

   type Project_Kind is
     (K_Configuration, K_Abstract,
      K_Standard, K_Library, K_Aggregate, K_Aggregate_Library);

   --
   --  Name / Value
   --

   subtype Name_Type is String
     with Dynamic_Predicate => Name_Type'Length > 0;

   subtype Value_Type is String;

end GPR2;

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

2016-07-06  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch3.adb (Analyze_Subtype_Declaration): For generated
	subtypes, such as actual subtypes of unconstrained formals,
	inherit predicate functions, if any, from the parent type rather
	than creating redundant new ones.


[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1056 bytes --]

Index: sem_ch3.adb
===================================================================
--- sem_ch3.adb	(revision 238040)
+++ sem_ch3.adb	(working copy)
@@ -4802,6 +4802,24 @@
       then
          Set_Has_Predicates (Id);
          Set_Has_Delayed_Freeze (Id);
+
+         --  Generated subtypes inherit the predicate function from the parent
+         --  (no aspects to examine on the generated declaration).
+
+         if not Comes_From_Source (N) then
+            Set_Ekind (Id, Ekind (T));
+
+            if Present (Predicate_Function (T)) then
+               Set_Predicate_Function (Id, Predicate_Function (T));
+
+            elsif Present (Ancestor_Subtype (T))
+              and then Has_Predicates (Ancestor_Subtype (T))
+              and then Present (Predicate_Function (Ancestor_Subtype (T)))
+            then
+               Set_Predicate_Function (Id,
+                 Predicate_Function (Ancestor_Subtype (T)));
+            end if;
+         end if;
       end if;
 
       --  Subtype of Boolean cannot have a constraint in SPARK

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-07-06 12:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-06 12:38 [Ada] Spurious error on container instantiation with predicated array type Arnaud Charlet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).