public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Checks on intrinsic operators
@ 2011-10-13 10:35 Arnaud Charlet
  2011-10-13 12:51 ` Iain Sandoe
  0 siblings, 1 reply; 2+ messages in thread
From: Arnaud Charlet @ 2011-10-13 10:35 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ed Schonberg

[-- Attachment #1: Type: text/plain, Size: 999 bytes --]

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.


[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 562 bytes --]

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;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Ada] Checks on intrinsic operators
  2011-10-13 10:35 [Ada] Checks on intrinsic operators Arnaud Charlet
@ 2011-10-13 12:51 ` Iain Sandoe
  0 siblings, 0 replies; 2+ messages in thread
From: Iain Sandoe @ 2011-10-13 12:51 UTC (permalink / raw)
  To: Arnaud Charlet; +Cc: gcc-patches, Ed Schonberg


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-10-13 12:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-13 10:35 [Ada] Checks on intrinsic operators Arnaud Charlet
2011-10-13 12:51 ` Iain Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).