re PR ada/15805 (Illegal program not detected, allows writing through access to constant)
authorSamuel Tardieu <sam@rfc1149.net>
Fri, 7 Dec 2007 14:35:22 +0000 (14:35 +0000)
committerSamuel Tardieu <sam@gcc.gnu.org>
Fri, 7 Dec 2007 14:35:22 +0000 (14:35 +0000)
    gcc/ada/
PR ada/15805
* sem_ch6.adb (Process_Formals): Prevent an access type formal
to be initialized with an access to constant object.

    gcc/testsuite/
PR ada/15805
* gnat.dg/specs/access_constants.ads: New test.

From-SVN: r130676

gcc/ada/ChangeLog
gcc/ada/sem_ch6.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/specs/access_constant.ads [new file with mode: 0644]

index 5a1033245775bf57ec3609d966053c9aca6c6da7..9ddc6da809fdbeb8de6cc292eae176bd7da69856 100644 (file)
@@ -1,3 +1,9 @@
+2007-12-07  Samuel Tardieu  <sam@rfc1149.net>
+
+       PR ada/15805
+       * sem_ch6.adb (Process_Formals): Prevent an access type formal
+       to be initialized with an access to constant object.
+
 2007-12-07  Olivier Hainque  <hainque@adacore.com>
 
        PR ada/34173
index 69064c28a80e5f5d7bd84987bbc1417fcf0c581b..b2451cb5eab8cd0df085a23ea695ac437d2c8f4d 100644 (file)
@@ -6998,6 +6998,20 @@ package body Sem_Ch6 is
 
             Analyze_Per_Use_Expression (Default, Formal_Type);
 
+            --  Check that an access to constant is not used with an
+            --  access type.
+
+            if Ekind (Formal_Type) = E_Anonymous_Access_Type
+              and then not Is_Access_Constant (Formal_Type)
+              and then Is_Access_Type (Etype (Default))
+              and then Is_Access_Constant (Etype (Default))
+            then
+               Error_Msg_NE ("parameter of type& cannot be initialized " &
+                             "with an access-to-constant expression",
+                             Default,
+                             Formal_Type);
+            end if;
+
             --  Check that the designated type of an access parameter's default
             --  is not a class-wide type unless the parameter's designated type
             --  is also class-wide.
index 12aad8cbc12d11faa331a4305d535d8a98455257..2342e5e3aed3d8f88bfd77ec1a704e16fddefa01 100644 (file)
@@ -1,3 +1,8 @@
+2007-12-07  Samuel Tardieu  <sam@rfc1149.net>
+
+       PR ada/15805
+       * gnat.dg/specs/access_constants.ads: New test.
+
 2007-12-07  Olivier Hainque  <hainque@adacore.com>
 
        PR ada/34173
diff --git a/gcc/testsuite/gnat.dg/specs/access_constant.ads b/gcc/testsuite/gnat.dg/specs/access_constant.ads
new file mode 100644 (file)
index 0000000..fa9829e
--- /dev/null
@@ -0,0 +1,13 @@
+-- { dg-do compile }
+package Access_Constant is
+
+   c: aliased constant integer := 3;
+
+   type const_ptr is access constant integer;
+   cp : const_ptr := c'access;
+
+   procedure inc (var_ptr: access integer :=
+     cp)  -- { dg-error "access-to-constant" }
+      is abstract;
+
+end Access_Constant;