OSDN Git Service

gcc/ada/
authorsam <sam@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 7 Dec 2007 14:35:22 +0000 (14:35 +0000)
committersam <sam@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 7 Dec 2007 14:35:22 +0000 (14:35 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@130676 138bc75d-0d04-0410-961f-82ee72b054a4

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 5a10332..9ddc6da 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 69064c2..b2451cb 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 12aad8c..2342e5e 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;