diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2024-11-13 09:42:01 +0100 |
---|---|---|
committer | Marc Poulhiès <dkm@gcc.gnu.org> | 2024-11-26 10:49:36 +0100 |
commit | e14ec5681e780626f59ef7b37d0648c2d6992a14 (patch) | |
tree | 802c0c11ba5e6a78e49979f331eaf470c9ca3b54 /gcc | |
parent | 38b977cc077d055be9730b6476043d666864c832 (diff) | |
download | gcc-e14ec5681e780626f59ef7b37d0648c2d6992a14.zip gcc-e14ec5681e780626f59ef7b37d0648c2d6992a14.tar.gz gcc-e14ec5681e780626f59ef7b37d0648c2d6992a14.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/sem_ch13.adb | 4 | ||||
-rw-r--r-- | 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 3597bce..2d13ecc 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 484c753..cc94b02 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 |