]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Reject attribute Initialize on unchecked unions
authorPiotr Trojanek <trojanek@adacore.com>
Thu, 22 Dec 2022 11:14:08 +0000 (12:14 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 15 May 2023 09:36:40 +0000 (11:36 +0200)
Attribute Initialized is expanded into Valid_Scalars, which can't work
on unchecked unions, so Initialized on unchecked unions needs to be
rejected before expansion.

gcc/ada/

* sem_attr.adb (Analyze_Attribute): Reject attribute Initialized
on unchecked unions; fix grammar in comment.

gcc/ada/sem_attr.adb

index a9e64b7655dbdbd23c9e436f6377c7640973d1fb..77c56aa587b71597f2fa9c3302b857b982748acc 100644 (file)
@@ -4613,7 +4613,7 @@ package body Sem_Attr is
 
          if Comes_From_Source (N) then
 
-            --  This attribute be prefixed with references to objects or
+            --  This attribute can be prefixed with references to objects or
             --  values (such as a current instance value given within a type
             --  or subtype aspect).
 
@@ -4621,6 +4621,13 @@ package body Sem_Attr is
               and then not Is_Current_Instance_Reference_In_Type_Aspect (P)
             then
                Error_Attr_P ("prefix of % attribute must be object");
+
+            --  Just like attribute 'Valid_Scalars this attribute is illegal
+            --  on unchecked union types.
+
+            elsif Has_Unchecked_Union (Validated_View (P_Type)) then
+               Error_Attr_P
+                 ("attribute % not allowed for Unchecked_Union type");
             end if;
          end if;