https://gcc.gnu.org/g:9420666b5a93e510f2f10470a000fd5b4f9401aa

commit r15-6132-g9420666b5a93e510f2f10470a000fd5b4f9401aa
Author: Viljar Indus <in...@adacore.com>
Date:   Thu Nov 14 15:22:44 2024 +0200

    ada: Avoid expanding LHS assignments for controlled types
    
    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.

Diff:
---
 gcc/ada/exp_ch6.adb | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index 7010256b1a94..7839b6716328 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -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.

Reply via email to