This is the mail archive of the 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] Detect illegal component of dereference of access-to-constant

This patch detects an error that was previously undetected. In particular, it
is illegal to rename a subcomponent of an object designated by an
access-to-constant value if that subcomponent depends on discriminants.
The following test should get an error:
% gnatmake -f -q acc_const_test.adb
acc_const_test.adb:17:46: illegal renaming of discriminant-dependent component
gnatmake: "acc_const_test.adb" compilation error

with Ada.Text_IO; use Ada.Text_IO;
procedure Acc_Const_Test is

   subtype Int is Integer range 1..100;

   type Desig (Discrim : Int := 1) is
         Discrim_Dependent : String (1..Discrim);
      end record;

   type Ref_Const is access constant Desig;

   Var : aliased Desig := (Discrim => 4, Discrim_Dependent => "abcd");

   Ref_Const_Obj : Ref_Const := Var'Access;

   Char : Character renames Ref_Const_Obj.all.Discrim_Dependent(4);
   -- Illegal in Ada 2005.

   Var := (Discrim => 1, Discrim_Dependent => "X");
   --  Raises C_E in Ada 95.

   Put_Line ("Char = " & Char);
end Acc_Const_Test;

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

2014-05-21  Bob Duff  <>

	* sem_util.adb (Is_Dependent_Component_Of_Mutable_Object):
	This was returning False if the Object is a constant view. Fix
	it to return True in that case, because it might be a view of
	a variable.
	(Has_Discriminant_Dependent_Constraint): Fix latent
	bug; this function was crashing when passed a discriminant.

Attachment: difs
Description: Text document

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