diff mbox

[Ada] Checks on intrinsic operators

Message ID 20111013102241.GA18403@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 13, 2011, 10:22 a.m. UTC
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  <schonberg@adacore.com>

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

Comments

Iain Sandoe Oct. 13, 2011, 12:08 p.m. UTC | #1
On 13 Oct 2011, at 11:22, Arnaud Charlet wrote:

> 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;

just out of curiosity, is there a reason why some of the changes  
applied say " x must do y " with an example - but the example is not  
made into a test-case?
(apologies if this has already be discussed).
Iain
diff mbox

Patch

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;