[Ada] Spurious error on equality operator on incomplete type

Message ID 20171215141118.GA97882@adacore.com
State New
Headers show
Series
  • [Ada] Spurious error on equality operator on incomplete type
Related show

Commit Message

Pierre-Marie de Rodat Dec. 15, 2017, 2:11 p.m.
This patch fixes a spurious error on a declaration for an equality
operator whose operands have an incomplete type, when the same declarative
oart includes another such equality operator on another incomplete type which
is used as an actual in an earlier instantiation.

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

gcc/ada/

2017-12-15  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch6.adb (Conformking_Types): Two incomplete types are conforming
	when one of them is used as a generic actual, but only within an
	instantiation.
	* einfo.ads: Clarify use of flag Used_As_Generic_Actual.

gcc/testsuite/

2017-12-15  Ed Schonberg  <schonberg@adacore.com>

	* gnat.dg/incomplete6.adb, gnat.dg/incomplete6.ads

Patch

Index: einfo.ads
===================================================================
--- einfo.ads	(revision 255690)
+++ einfo.ads	(working copy)
@@ -4583,7 +4583,9 @@ 
 
 --    Used_As_Generic_Actual (Flag222)
 --       Defined in all entities, set if the entity is used as an argument to
---       a generic instantiation. Used to tune certain warning messages.
+--       a generic instantiation. Used to tune certain warning messages, and
+--       in checking type conformance within an instantiation that involves
+--       incomplete formal and actual types.
 
 --    Uses_Lock_Free (Flag188)
 --       Defined in protected type entities. Set to True when the Lock Free
Index: sem_ch6.adb
===================================================================
--- sem_ch6.adb	(revision 255693)
+++ sem_ch6.adb	(working copy)
@@ -7666,10 +7666,12 @@ 
          return True;
 
       --  In Ada 2012, incomplete types (including limited views) can appear
-      --  as actuals in instantiations.
+      --  as actuals in instantiations, where they are conformant to the
+      --  corresponding incomplete formal.
 
       elsif Is_Incomplete_Type (Type_1)
         and then Is_Incomplete_Type (Type_2)
+        and then In_Instance
         and then (Used_As_Generic_Actual (Type_1)
                    or else Used_As_Generic_Actual (Type_2))
       then
Index: ../testsuite/gnat.dg/incomplete6.adb
===================================================================
--- ../testsuite/gnat.dg/incomplete6.adb	(revision 0)
+++ ../testsuite/gnat.dg/incomplete6.adb	(revision 0)
@@ -0,0 +1,15 @@ 
+--  { dg-do compile }
+
+package body Incomplete6 is
+
+   function "=" (Left, Right : Vint) return Boolean is
+   begin
+      return Left.Value = Right.Value;
+   end;
+   
+   function "=" (Left, Right : Vfloat) return Boolean is
+   begin
+      return Left.Value = Right.Value;
+   end;
+
+end;
Index: ../testsuite/gnat.dg/incomplete6.ads
===================================================================
--- ../testsuite/gnat.dg/incomplete6.ads	(revision 0)
+++ ../testsuite/gnat.dg/incomplete6.ads	(revision 0)
@@ -0,0 +1,22 @@ 
+with Ada.Unchecked_Conversion;
+
+package Incomplete6 is
+   
+   type Vint;
+   function "=" (Left, Right : Vint) return Boolean;
+
+   type Vint is record
+      Value : Integer;
+   end record;
+
+   function To_Integer is new 
+     Ada.Unchecked_Conversion(Source => Vint, Target => Integer);
+   
+   type Vfloat;
+   function "=" (Left, Right : in Vfloat) return Boolean;
+
+   type Vfloat is record
+      Value : Float;
+   end record;
+
+end;