]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix iteration over component items with pragmas
authorPiotr Trojanek <trojanek@adacore.com>
Tue, 21 Mar 2023 08:46:57 +0000 (09:46 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Fri, 26 May 2023 07:29:16 +0000 (09:29 +0200)
Component items in a record declaration might include pragmas, which
must be ignored when detecting components with default expressions.

More a code cleanup than a bugfix, as it only affects artificial corner
cases. Found while fixing missing legality checks for variant component
declarations.

gcc/ada/

* sem_ch3.adb (Check_CPP_Type_Has_No_Defaults): Iterate with
First_Non_Pragma and Next_Non_Pragma.
* exp_dist.adb (Append_Record_Traversal): Likewise.

gcc/ada/exp_dist.adb
gcc/ada/sem_ch3.adb

index 8f62bef2c649cc8214941548ca8cb86f0e704569..f025b5656c6c60aac0bd9fa0d8fa1f9b03379062 100644 (file)
@@ -8304,7 +8304,7 @@ package body Exp_Dist is
             CI := Component_Items (Clist);
             VP := Variant_Part (Clist);
 
-            Item := First (CI);
+            Item := First_Non_Pragma (CI);
             while Present (Item) loop
                Def := Defining_Identifier (Item);
 
@@ -8313,7 +8313,7 @@ package body Exp_Dist is
                     (Stmts, Container, Counter, Rec, Def);
                end if;
 
-               Next (Item);
+               Next_Non_Pragma (Item);
             end loop;
 
             if Present (VP) then
index 9e32dea5c02cdda57ca2846280ebae7c22ecf28d..fb4f5badd4e77adefaec354acd2ea01187b16444 100644 (file)
@@ -12312,7 +12312,7 @@ package body Sem_Ch3 is
       --  Check all components to ensure no default expressions
 
       if Present (Clist) then
-         Comp := First (Component_Items (Clist));
+         Comp := First_Non_Pragma (Component_Items (Clist));
          while Present (Comp) loop
             if Present (Expression (Comp)) then
                Error_Msg_N
@@ -12320,7 +12320,7 @@ package body Sem_Ch3 is
                   & "default expression", Expression (Comp));
             end if;
 
-            Next (Comp);
+            Next_Non_Pragma (Comp);
          end loop;
       end if;
    end Check_CPP_Type_Has_No_Defaults;