https://gcc.gnu.org/g:e14ec5681e780626f59ef7b37d0648c2d6992a14

commit r15-5690-ge14ec5681e780626f59ef7b37d0648c2d6992a14
Author: Eric Botcazou <ebotca...@adacore.com>
Date:   Wed Nov 13 09:42:01 2024 +0100

    ada: Minor adjustments to error message for RM B.1(24)
    
    The RM B.1(24) sub-clause says that imported entities cannot be initialized
    and it is checked in three contexts, aspect Import, pragma Import and pragma
    Import_Object, with slightly different error messages.  Moreover, for the
    aspect, the error is given twice because that of the pragma is also given.
    
    In addition, if the initialization expression is an aggregate that is not
    static, the error is given only for the aspect and not for the two pragmas.
    
    This change aligns the error messages on that of pragma Import and plugs the
    aforementioned loophole for the two pragmas.
    
    gcc/ada/ChangeLog:
    
            * sem_ch13.adb (Analyze_Aspect_Export_Import): Add explicit mention
            of the declaration in the error message for the Import.
            * sem_prag.adb (Process_Extended_Import_Export_Object_Pragma): Also
            test Has_Init_Expression on the declaration node for Import_Object
            and use the same wording as that of Import.
            (Process_Import_Or_Interface): Also test Has_Init_Expression on the
            declaration node for Import.

Diff:
---
 gcc/ada/sem_ch13.adb |  4 ++++
 gcc/ada/sem_prag.adb | 21 ++++++++++++---------
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 3597bceb3cce..2d13ecc2f983 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -1903,6 +1903,10 @@ package body Sem_Ch13 is
                      if Nkind (N) = N_Object_Declaration
                        and then Present (Expression (N))
                      then
+                        Error_Msg_Sloc := Sloc (Defining_Identifier (N));
+                        Error_Msg_N
+                          ("no initialization allowed for declaration of& #",
+                           Defining_Identifier (N));
                         Error_Msg_N
                           ("imported entities cannot be initialized "
                            & "(RM B.1(24))", Expression (N));
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 484c7538bbf8..cc94b02e43ce 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -9169,15 +9169,17 @@ package body Sem_Prag is
             --  initialization generated by the code generator, e.g. for an
             --  access type, does not count here.
 
-            elsif Present (Expression (Parent (Def_Id)))
-               and then
-                 Comes_From_Source
-                   (Original_Node (Expression (Parent (Def_Id))))
+            elsif (Present (Expression (Parent (Def_Id)))
+                    and then
+                      Comes_From_Source
+                        (Original_Node (Expression (Parent (Def_Id)))))
+              or else Has_Init_Expression (Parent (Def_Id))
             then
                Error_Msg_Sloc := Sloc (Def_Id);
                Error_Pragma_Arg
-                 ("imported entities cannot be initialized (RM B.1(24))",
-                  "\no initialization allowed for & declared#", Arg1);
+                 ("no initialization allowed for declaration of& #",
+                  "\imported entities cannot be initialized (RM B.1(24))",
+                  Arg1);
             else
                Set_Imported (Def_Id);
                Note_Possible_Modification (Arg_Internal, Sure => False);
@@ -9740,9 +9742,10 @@ package body Sem_Prag is
             --  only counts if it comes from source, otherwise it is simply
             --  the code generator making an implicit initialization explicit.
 
-            elsif Present (Expression (Parent (Def_Id)))
-              and then Comes_From_Source
-                         (Original_Node (Expression (Parent (Def_Id))))
+            elsif (Present (Expression (Parent (Def_Id)))
+                    and then Comes_From_Source
+                               (Original_Node (Expression (Parent (Def_Id)))))
+               or else Has_Init_Expression (Parent (Def_Id))
             then
                --  Set imported flag to prevent cascaded errors

Reply via email to