In Ada 2012, boolean aspects are True by default, but can specify explicitly
a value of False. In the case of an Import aspect, this indicates that the
corresponding entity must have a completion in Ada, and not in the language
specified in a Convention aspect.

Compiling main.adb must yield:

    main.adb:4:04: missing body for "Get_Length"

---
with Interfaces.C; with Ada.Text_IO;
procedure Main is
   
   function Get_Length return Interfaces.C.size_t with
      Convention    => C,
      Import        => False,
      External_Name => "getLength";

begin
   Ada.Text_IO.Put_Line(Get_Length'Img);
end Main;

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

2014-08-04  Ed Schonberg  <schonb...@adacore.com>

        * sem_prag.adb (Process_Import_Or_Interface): Handle properly
        an aspect Import that specifies a False value.

Index: sem_prag.adb
===================================================================
--- sem_prag.adb        (revision 213553)
+++ sem_prag.adb        (working copy)
@@ -7993,7 +7993,37 @@
                      end if;
                   end;
 
-                  Set_Has_Completion (Def_Id);
+                  --  If the pragma comes from an aspect specification, there
+                  --  must be an Import aspect specified as well. In the rare
+                  --  case where Import is set to False, the suprogram needs to
+                  --  have a local completion.
+
+                  declare
+                     Imp_Aspect : constant Node_Id :=
+                                    Find_Aspect (Def_Id, Aspect_Import);
+                     Expr       : Node_Id;
+
+                  begin
+                     if Present (Imp_Aspect)
+                       and then Present (Expression (Imp_Aspect))
+                     then
+                        Expr := Expression (Imp_Aspect);
+                        Analyze_And_Resolve (Expr, Standard_Boolean);
+
+                        if Is_Entity_Name (Expr)
+                          and then Entity (Expr) = Standard_True
+                        then
+                           Set_Has_Completion (Def_Id);
+                        end if;
+
+                     --  If there is no expression, the default is True, as for
+                     --  all boolean aspects. Same for the older pragma.
+
+                     else
+                        Set_Has_Completion (Def_Id);
+                     end if;
+                  end;
+
                   Process_Interface_Name (Def_Id, Arg3, Arg4);
                end if;
 

Reply via email to