]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Spurious warning about premature use of selected component
authorEd Schonberg <schonberg@adacore.com>
Thu, 24 Dec 2020 01:21:13 +0000 (20:21 -0500)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 3 May 2021 09:28:22 +0000 (05:28 -0400)
gcc/ada/

* sem_warn.adb (Check_References): Do not emit warning on a
selected component when enclosing type has no discriminant and
type of component has partial initialization.

gcc/ada/sem_warn.adb

index b5275a8b019da683b389d79da0a13c85702fc875..0be6b39c79604a66902964f2a2689fc671859ae7 100644 (file)
@@ -1523,6 +1523,17 @@ package body Sem_Warn is
                         --  uninitialized component to get a better message.
 
                      elsif Nkind (Parent (UR)) = N_Selected_Component then
+                        --  Suppress possibly superfluous warning if component
+                        --  is known to exist and is partially initialized.
+
+                        if not Has_Discriminants (Etype (E1))
+                          and then
+                            Is_Partially_Initialized_Type
+                              (Etype (Parent (UR)), False)
+                        then
+                           goto Continue;
+                        end if;
+
                         Error_Msg_Node_2 := Selector_Name (Parent (UR));
 
                         if not Comes_From_Source (Parent (UR)) then