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 bug in handling of UC


Tested on i686-linux. Committed on mainline.

An instantiation of unchecked_conversion creates a wrapper package for
the function, whose return type is a subtype that renames the actual.
This patch uses the actual for the subsequent unchecked_conversion, rather
than the internal subtype. This is both semantically correct, and prevents
spurious errors in gigi, when the of the unchecked conversion is operand
to a binary operation.
Test case: the following must compile quietly:

with Ada.Unchecked_Conversion;
package Pkg is
   use Ada;
   type Node_Rec(<>) is limited private;
   package Node_Types is
      type SCIL_Node is private;
      type Decl_Region is private;
   private
      type SCIL_Node is access all Node_Rec;
      for SCIL_Node'Storage_Size use 0;
      type Decl_Region is new SCIL_Node;
   end Node_Types;
   type SCIL_Node is new Node_Types.SCIL_Node;
   type Decl_Region is new Node_Types.Decl_Region;
   function "+" (Node: Decl_Region) return SCIL_Node;
private
   type Node_Rec (B : Boolean) is record null; end record;
   type Node_Ptr is access all Node_Rec;
   function From_Node_Ptr is new Unchecked_Conversion (Node_Ptr, Decl_Region);
end Pkg;
package body Pkg is
   function "+" (Node: Decl_Region) return SCIL_Node is
      function Cast is new Unchecked_Conversion (Decl_Region, SCIL_Node);
   begin
      if (Node /= From_Node_Ptr(null)) then null; end if;
      return Cast(Node);
   end "+";
end Pkg;

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

	* exp_intr.adb (Expand_Unc_Conversion): As a target type, use the type
	that appears in the instantiation rather than the internal subtype
	generated in the wrapper package, to avoid anomalies in gigi when the
	target is derived from a private type whose full view is an access type.

Attachment: difs.16
Description: Text document


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