diff mbox

[Ada] Fix regression in imported C++ type that cover interface primitives

Message ID 20101026130540.GA5004@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 26, 2010, 1:05 p.m. UTC
This patch fixes a regression of the compiler in the management of imported
C++ types that cover interfaces. The following test now compiles without
errors.

package Animals is
   type Carnivore is limited interface;
   function Number_Of_Teeth (X : Carnivore) return Natural is abstract;
   pragma Convention (CPP, Number_Of_Teeth);

   type Animal is tagged limited null record;
   pragma Import (CPP, Animal);

   type Dog is new Animal and Carnivore with null record;
   pragma Import (CPP, Dog);

   function Number_Of_Teeth (A : Dog) return Natural;
   pragma Import (CPP, Number_Of_Teeth);
end Animals;

Command: gcc -c -gnat05 animals.ads -gnatws

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

2010-10-26  Javier Miranda  <miranda@adacore.com>

	* sem_prag.adb (Process_Import_Or_Interface): Skip primitives of
	interface types when processing all the entities in the homonym chain
	that are declared in the same declarative part.
diff mbox

Patch

Index: sem_prag.adb
===================================================================
--- sem_prag.adb	(revision 165941)
+++ sem_prag.adb	(working copy)
@@ -3928,6 +3928,14 @@  package body Sem_Prag is
                then
                   null;
 
+               --  The pragma does not apply to primitives of interfaces
+
+               elsif Is_Dispatching_Operation (Def_Id)
+                 and then Present (Find_Dispatching_Type (Def_Id))
+                 and then Is_Interface (Find_Dispatching_Type (Def_Id))
+               then
+                  null;
+
                --  Verify that the homonym is in the same declarative part (not
                --  just the same scope).
 
@@ -4047,10 +4055,10 @@  package body Sem_Prag is
            and then C = Convention_CPP
          then
             --  Types treated as CPP classes are treated as limited, but we
-            --  don't require them to be declared this way. A warning is
-            --  issued to encourage the user to declare them as limited.
-            --  This is not an error, for compatibility reasons, because
-            --  these types have been supported this way for some time.
+            --  don't require them to be declared this way. A warning is issued
+            --  to encourage the user to declare them as limited. This is not
+            --  an error, for compatibility reasons, because these types have
+            --  been supported this way for some time.
 
             if not Is_Limited_Type (Def_Id) then
                Error_Msg_N