From: Eric Botcazou Date: Thu, 20 Nov 2025 22:25:15 +0000 (+0100) Subject: ada: Give consistent error message for invalid prefix in select component X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b2e181b1f87ea186ca5d382b12a0fed53c94c64;p=thirdparty%2Fgcc.git ada: Give consistent error message for invalid prefix in select component This gives a consistent error message for an invalid prefix in all the cases where the prefix has been found to be the name of an entity. gcc/ada/ChangeLog: * sem_ch4.adb (Analyze_Selected_Component): Give a specific error message for an invalid prefix that is the dereference of a name. * sem_ch8.adb (Find_Selected_Component): Give a consistent error message for the name of an invalid prefix. --- diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index fa98d120a74..1a9e37ce92d 100644 --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -6152,9 +6152,22 @@ package body Sem_Ch4 is then return; - else - -- Invalid prefix + -- Invalid prefix. If it is the dereference of a name, we give the same + -- error message as would be given if the dereference was implicit. + + elsif Nkind (Pref) = N_Explicit_Dereference + and then Is_Entity_Name (Prefix (Pref)) + then + Error_Msg_N + ("invalid prefix& in selected component", Prefix (Pref)); + if Is_Incomplete_Type (Etype (Pref)) then + Error_Msg_N + ("\dereference must not be of an incomplete type " + & "(RM 3.10.1)", Prefix (Pref)); + end if; + + else Error_Msg_NE ("invalid prefix in selected component&", N, Sel); end if; diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb index 8f534af7e1b..720e7f71662 100644 --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -8585,8 +8585,7 @@ package body Sem_Ch8 is if Ekind (P_Name) /= E_Function and then not Is_Overloaded (P) then - Error_Msg_NE - ("invalid prefix& in selected component", N, P_Name); + Error_Msg_N ("invalid prefix& in selected component", P); Diagnose_Call; return; @@ -8711,7 +8710,7 @@ package body Sem_Ch8 is end if; end; - Error_Msg_N ("invalid prefix in selected component&", P); + Error_Msg_N ("invalid prefix& in selected component", P); if Is_Incomplete_Type (P_Type) and then Is_Access_Type (Etype (P)) @@ -8722,7 +8721,7 @@ package body Sem_Ch8 is end if; else - Error_Msg_N ("invalid prefix in selected component", P); + Error_Msg_N ("invalid prefix& in selected component", P); end if; end if; else