Patchwork [Ada] Fix bad warning for unmodified pragma and unbounded string

login
register
mail settings
Submitter Arnaud Charlet
Date Oct. 18, 2010, 9:53 a.m.
Message ID <20101018095332.GA25805@adacore.com>
Download mbox | patch
Permalink /patch/68155/
State New
Headers show

Comments

Arnaud Charlet - Oct. 18, 2010, 9:53 a.m.
This patch fixes the error of the compiler sometimes giving a
warning for a pragma Unmodified when the object is only referenced
but has a component of type Unbounded_String. The following test
compiles quietly with no switches (it used to give a bogus warning
on line 14.

     1. with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
     2. procedure Unmodunbs is
     3.   type Rec is record
     4.     U : Unbounded_String;
     5.   end record;
     6.   S1, S2, s3 : Rec;
     7.   pragma Unmodified (S2);
     8.   pragma Unreferenced (S3);
     9.
    10.   U1, U2, U3 : Unbounded_String;
    11.   pragma Unmodified (U2);
    12.   pragma Unreferenced (U3);
    13. begin
    14.   S1 := S2;
    15.   U1 := U2;
    16. end;

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

2010-10-18  Robert Dewar  <dewar@adacore.com>

	* sem_util.adb (Note_Possible_Modification): Do not give warning for
	use of pragma Unmodified unless we are sure this is a modification.

Patch

Index: sem_util.adb
===================================================================
--- sem_util.adb	(revision 165614)
+++ sem_util.adb	(working copy)
@@ -9451,7 +9451,10 @@  package body Sem_Util is
                if Comes_From_Source (Exp)
                  or else Modification_Comes_From_Source
                then
-                  if Has_Pragma_Unmodified (Ent) then
+                  --  Give warning if pragma unmodified given and we are
+                  --  sure this is a modification.
+
+                  if Has_Pragma_Unmodified (Ent) and then Sure then
                      Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
                   end if;