This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Fix for AI 264 and AI 384


Tested on x86-linux, committed on mainline.

Fixes Ada 2005 AI-264 and AI-384.

In Ada95, the predefined fixed*fixed operators are defined so that they
invariably hide user-defined fixed*fixed operators, making these useless.
AI-264 supplies a name resolution rule that makes the predefined operators
visible if there is no user-defined candidate operation on the types. The
predefined operation is still available in the context of a conversion.
test case fix.adb: must diagnose three semantic errors.
--
$ gcc -c -gnat05 fix.adb
fix.adb:27:13: there is no applicable operator "*" for type "T1" defined at line 2
fix.adb:29:13: invalid operand types for operator "/"
fix.adb:29:13: left operand has type "T1" defined at line 2
fix.adb:29:13: right operand has type "T2" defined at line 3
fix.adb:31:13: there is no applicable operator "*" for type "T3" defined at line 4
--
procedure fix is
   type T1 is delta 0.1 range -10.0 .. 10.0;
   type T2 is delta 0.001 range -10.0 .. 10.0;
   type T3 is delta 0.0001 range -10.0 .. 10.0;
   function "*"(Left : T1; Right : T2) return T3 is
   begin
      return T3'last;
   end;

   function "*"(Left : T2; Right : T1) return T3 is
   begin
      return T3'last;
   end;
   function "/"(Left : T3; Right : T1) return T2 is
   begin
      return T2'last;
   end;
   function "/"(Left : T3; Right : T2) return T1 is
   begin
      return T1'last;
   end;

   X1, Y1 : T1 := 0.5;
   X2, Y2 : T2 := 0.5;
   X3     : T3;
 begin
   X3 := X1 * X1;  -- Error! Does not use universal-fixed operator, and
                   -- no user-defined operator works either
   X3 := X1 / X2;  -- Error! Does not use universal-fixed operator,
                   -- and no user-defined operator works either
   X3 := X3 * X3;  -- Error! Does not use universal-fixed operator (because
                   -- X3 has a primitive which is fixed * fixed, even though
                   -- X3 appears only as result type).
end fix;
--

2005-01-03  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch4.adb (Has_Fixed_Op): New predicate in Check_Arithmetic_Pair,
	to determine whether one of the operands is a fixed-point type for
	which a user-defined multiplication or division operation might be
	defined.

	* sem_res.adb (Valid_Conversion): The legality rules for conversions
	of access types are symmetric in Ada 2005: either designated type can
	be unconstrained.

Attachment: difs.22
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]