An operator can be declared Import (Intrinsic) only if the current view of the
operand type (s) is a numeric type. With this patch the compiler properly
rejects the pragma if the operand type is private or incomplete.

Compiling mysystem.ads must yield:

   mysystem.ads:3:13: intrinsic operator can only apply to numeric types
   mysystem.ads:7:13: intrinsic operator can only apply to numeric types
   mysystem.ads:7:18: invalid use of incomplete type "Self"

---
package Mysystem is
   type A is private;
   function "<"  (Left, Right : A) return Boolean;
   pragma Import (Intrinsic, "<");

   type Self;
   function "+" (X, Y : Self) return Boolean;
   pragma Import (Intrinsic, "+");
   type Self is tagged null record;
private
   type A is mod 2 ** 32;
end Mysystem;

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

2011-10-13  Ed Schonberg  <schonb...@adacore.com>

        * sem_intr.adb (Check_Intrinsic_Operator): Check that type
        is fully defined before checking that it is a numeric type.

Index: sem_intr.adb
===================================================================
--- sem_intr.adb        (revision 179894)
+++ sem_intr.adb        (working copy)
@@ -317,7 +317,11 @@
          return;
       end if;
 
-      if not Is_Numeric_Type (Underlying_Type (T1)) then
+      --  The type must be fully defined and numeric.
+
+      if No (Underlying_Type (T1))
+        or else not Is_Numeric_Type (Underlying_Type (T1))
+      then
          Errint ("intrinsic operator can only apply to numeric types", E, N);
       end if;
    end Check_Intrinsic_Operator;

Reply via email to