[Ada] Failure to detect redeclaration of constant with initial aggregate value

Arnaud Charlet charlet@adacore.com
Fri Jan 24 15:00:00 GMT 2014


This patch fixes an omission in the detection of illegal redeclarations of
constants whose previous full declaration includes an expression that is an
aggregate.

Compiling double.adb must be rejected with:

   double.adb:5:04: "Data_1" conflicts with declaration at line 3

---
procedure Double is
   type Arr is array (1..10) of Integer;
   Data_1 : constant Arr := (1 => 1, others => 0);

   Data_1 : constant Arr := (others => 5);
begin
   null;
end;

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

2014-01-24  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch3.adb (Constant_Redeclaration): New declaration is
	illegal if previous one has an initial expression that is an
	aggregate expanded into assignments.

-------------- next part --------------
Index: sem_ch3.adb
===================================================================
--- sem_ch3.adb	(revision 207039)
+++ sem_ch3.adb	(working copy)
@@ -11104,10 +11104,13 @@
       --  If previous full declaration or a renaming declaration exists, or if
       --  a homograph is present, let Enter_Name handle it, either with an
       --  error or with the removal of an overridden implicit subprogram.
+      --  The previous one is a full declaration if it has an expression
+      --  (which in the case of an aggregate is indicated by the Init flag).
 
       if Ekind (Prev) /= E_Constant
         or else Nkind (Parent (Prev)) = N_Object_Renaming_Declaration
         or else Present (Expression (Parent (Prev)))
+        or else Has_Init_Expression (Parent (Prev))
         or else Present (Full_View (Prev))
       then
          Enter_Name (Id);


More information about the Gcc-patches mailing list