OSDN Git Service

gcc/ada/
authorsam <sam@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 7 Dec 2007 14:37:36 +0000 (14:37 +0000)
committersam <sam@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 7 Dec 2007 14:37:36 +0000 (14:37 +0000)
* sem_ch3.adb (Analyze_Object_Declaration): Signal an error
when an access to constant is used to initialize an access
value.

    gcc/testsuite/
* gnat.dg/specs/access_constant_decl.ads: New test.

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

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

index 9ddc6da..cd4e3a0 100644 (file)
@@ -4,6 +4,10 @@
        * sem_ch6.adb (Process_Formals): Prevent an access type formal
        to be initialized with an access to constant object.
 
+       * sem_ch3.adb (Analyze_Object_Declaration): Signal an error
+       when an access to constant is used to initialize an access
+       value.
+
 2007-12-07  Olivier Hainque  <hainque@adacore.com>
 
        PR ada/34173
index 5c61d00..c16b406 100644 (file)
@@ -2364,6 +2364,20 @@ package body Sem_Ch3 is
 
          Set_Is_True_Constant (Id, True);
 
+         --  If the initialization expression is an access to constant,
+         --  it cannot be used with an access type.
+
+         if Is_Access_Type (Etype (E))
+           and then Is_Access_Constant (Etype (E))
+           and then Is_Access_Type (T)
+           and then not Is_Access_Constant (T)
+         then
+            Error_Msg_NE ("object of type& cannot be initialized with " &
+                          "an access-to-constant expression",
+                          E,
+                          T);
+         end if;
+
          --  If we are analyzing a constant declaration, set its completion
          --  flag after analyzing the expression.
 
index 2342e5e..2dcabc1 100644 (file)
@@ -3,6 +3,8 @@
        PR ada/15805
        * gnat.dg/specs/access_constants.ads: New test.
 
+       * gnat.dg/specs/access_constant_decl.ads: New test.
+
 2007-12-07  Olivier Hainque  <hainque@adacore.com>
 
        PR ada/34173
diff --git a/gcc/testsuite/gnat.dg/specs/access_constant_decl.ads b/gcc/testsuite/gnat.dg/specs/access_constant_decl.ads
new file mode 100644 (file)
index 0000000..aec40e6
--- /dev/null
@@ -0,0 +1,11 @@
+-- { dg-do compile }
+package Access_Constant_Decl is
+
+   c: aliased constant integer := 3;
+
+   type const_ptr is access constant integer;
+   cp : const_ptr := c'access;
+
+   x : access integer := cp; -- { dg-error "access-to-constant" }
+
+end Access_Constant_Decl;