]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Avoid expanding LHS assignments for controlled types
authorViljar Indus <indus@adacore.com>
Thu, 14 Nov 2024 13:22:44 +0000 (15:22 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 12 Dec 2024 09:57:54 +0000 (10:57 +0100)
Expanding a function call that returns a controlled type
on the left-hand side of an assignment should be avoided.
Otherwise we will miss the diagnostic for
trying to assign something to a non-variable element.

gcc/ada/ChangeLog:

* exp_ch6.adb (Expand_Ctrl_Function_Call): Avoid expansion
of controlled types when the LHS is a function call.

gcc/ada/exp_ch6.adb

index 7010256b1a942e248cfeaf9140bf6e711e2b327c..7839b67163287d0ea221468bf1e822ad720aedea 100644 (file)
@@ -5356,6 +5356,13 @@ package body Exp_Ch6 is
          return;
       end if;
 
+      --  Avoid expansions to catch an error when the function call is on the
+      --  left-hand side of an assignment.
+
+      if Nkind (Par) = N_Assignment_Statement and then N = Name (Par) then
+         return;
+      end if;
+
       --  Resolution is now finished, make sure we don't start analysis again
       --  because of the duplication.