diff mbox series

[COMMITTED,11/13] ada: Compiler accepts an illegal Unchecked_Access attribute reference

Message ID 20240702132130.523603-11-poulhies@adacore.com
State New
Headers show
Series [COMMITTED,01/13] ada: Document that -gnatdJ is unused | expand

Commit Message

Marc Poulhiès July 2, 2024, 1:21 p.m. UTC
From: Steve Baird <baird@adacore.com>

The compiler incorrectly accepts Some_Object'Unchecked_Access'Image.

gcc/ada/

	* sem_attr.adb
	(Analyze_Image_Attribute.Check_Image_Type): Check for
	E_Access_Attribute_Type prefix type.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_attr.adb | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index d56c25a79cc..0b0adac1126 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -1582,6 +1582,13 @@  package body Sem_Attr is
             then
                Error_Msg_Ada_2022_Feature ("nonscalar ''Image", Sloc (P));
                Error_Attr;
+
+            elsif Present (Image_Type)
+              and then Ekind (Image_Type) = E_Access_Attribute_Type
+            then
+               --  reject Some_Object'[Unchecked_]Access'[Wide_[Wide_]]Image
+               Error_Msg_N ("illegal Image attribute prefix", N);
+               Error_Attr;
             end if;
          end Check_Image_Type;