Before this commit, the following piece of code:

procedure Main is
function F (X : access Integer) return Boolean with Import;
begin
   null;
end;

Resulted in the following error messages:

main.adb:2:59: error: ";" should be "is"
main.adb:5:01: error: "end F;" expected
main.adb:5:01: error: missing "begin" for procedure "Main" at line 1

The problem was that GNAT incorrectly thought `F` required a body, and
thus assumed that the `begin` keyword belonged to `F` rather than to
Main.

The solution is to teach GNAT to not treat imported subprograms as
requiring a body.

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

gcc/ada/

        * par-ch6.adb (Contains_Import_Aspect): New function.
        (P_Subprogram): Acknowledge `Import` aspects.
diff --git a/gcc/ada/par-ch6.adb b/gcc/ada/par-ch6.adb
--- a/gcc/ada/par-ch6.adb
+++ b/gcc/ada/par-ch6.adb
@@ -201,6 +201,28 @@ package body Ch6 is
    --  Error recovery: cannot raise Error_Resync
 
    function P_Subprogram (Pf_Flags : Pf_Rec) return Node_Id is
+
+      function Contains_Import_Aspect (Aspects : List_Id) return Boolean;
+      --  Return True if Aspects contains an Import aspect.
+
+      ----------------------------
+      -- Contains_Import_Aspect --
+      ----------------------------
+
+      function Contains_Import_Aspect (Aspects : List_Id) return Boolean is
+         Aspect : Node_Id := First (Aspects);
+      begin
+         while Present (Aspect) loop
+            if Chars (Identifier (Aspect)) = Name_Import then
+               return True;
+            end if;
+
+            Next (Aspect);
+         end loop;
+
+         return False;
+      end Contains_Import_Aspect;
+
       Specification_Node : Node_Id;
       Name_Node          : Node_Id;
       Aspects            : List_Id;
@@ -982,10 +1004,12 @@ package body Ch6 is
          if Pf_Flags.Pbod
 
            --  Disconnect this processing if we have scanned a null procedure
-           --  because in this case the spec is complete anyway with no body.
+           --  or an Import aspect because in this case the spec is complete
+           --  anyway with no body.
 
            and then (Nkind (Specification_Node) /= N_Procedure_Specification
                       or else not Null_Present (Specification_Node))
+           and then not Contains_Import_Aspect (Aspects)
          then
             SIS_Labl := Scopes (Scope.Last).Labl;
             SIS_Sloc := Scopes (Scope.Last).Sloc;


Reply via email to