This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] ada: An access to non-constant cannot cover an access to constant
- From: Samuel Tardieu <sam at rfc1149 dot net>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 27 Nov 2007 10:04:11 +0100
- Subject: [PATCH] ada: An access to non-constant cannot cover an access to constant
- Organisation: RFC1149 (see http://www.rfc1149.net/)
gcc/ada/
PR ada/15805
* sem_type.adb (Covers): An access to non-constant cannot cover
an access to constant.
gcc/testsuite/
PR ada/15805
* gnat.dg/specs/access_constants.ads: New test.
---
gcc/ada/sem_type.adb | 10 ++++++++++
gcc/testsuite/gnat.dg/specs/access_constant.ads | 13 +++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)
create mode 100644 gcc/testsuite/gnat.dg/specs/access_constant.ads
diff --git a/gcc/ada/sem_type.adb b/gcc/ada/sem_type.adb
index 4612ad3..981da8c 100644
--- a/gcc/ada/sem_type.adb
+++ b/gcc/ada/sem_type.adb
@@ -878,6 +878,16 @@ package body Sem_Type is
then
return True;
+ -- An access to constant type can never be covered by a regular
+ -- access type.
+
+ elsif Is_Access_Type (T1)
+ and then not Is_Access_Constant (T1)
+ and then Is_Access_Type (T2)
+ and then Is_Access_Constant (T2)
+ then
+ return False;
+
-- If the expected type is an anonymous access, the designated type must
-- cover that of the expression. Use the base type for this check: even
-- though access subtypes are rare in sources, they are generated for
diff --git a/gcc/testsuite/gnat.dg/specs/access_constant.ads b/gcc/testsuite/gnat.dg/specs/access_constant.ads
new file mode 100644
index 0000000..039a24b
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/access_constant.ads
@@ -0,0 +1,13 @@
+-- { dg-do compile }
+-- { dg-excess-errors "multi-line error" }
+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 "expected an access type" }
+
+end Access_Constant;
--
1.5.3.6