https://gcc.gnu.org/g:19ee311f058de72972abb02a5e2981503f07350d
commit r17-1185-g19ee311f058de72972abb02a5e2981503f07350d Author: Ronan Desplanques <[email protected]> Date: Thu Apr 9 14:51:33 2026 +0200 ada: Fix indentation checks with "finally" When the parser encounters the word "finally", it first considers it an identifier and then looks ahead and possibly recategorizes it as a keyword. The expected level of indentation depends on the final verdict, but indentation checks were performed right away. This patch fixes the issue by delaying the checks appropriately. gcc/ada/ChangeLog: * par.adb, par-util.adb (Check_Bad_Layout_At): New procedure. * par-ch3.adb (P_Declarative_Item): Use new procedure. * par-ch5.adb (P_Sequence_Of_Statements): Likewise. Diff: --- gcc/ada/par-ch3.adb | 6 +++++- gcc/ada/par-ch5.adb | 4 ++-- gcc/ada/par-util.adb | 13 +++++++++++++ gcc/ada/par.adb | 3 +++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gcc/ada/par-ch3.adb b/gcc/ada/par-ch3.adb index 77c6f12691ae..c2f8eaf6c9db 100644 --- a/gcc/ada/par-ch3.adb +++ b/gcc/ada/par-ch3.adb @@ -4613,7 +4613,7 @@ package body Ch3 is Append (P_Generic, Decls); when Tok_Identifier => - Check_Bad_Layout; + Save_Scan_State (Scan_State); -- Special check for misuse of overriding not in Ada 2005 mode @@ -4632,6 +4632,10 @@ package body Ch3 is P_Identifier_Declarations (Decls, Done, In_Spec, In_Statements); end if; + if not Done then + Check_Bad_Layout_At (Scan_State); + end if; + when Tok_Package => Check_Bad_Layout; Append (P_Package (Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp), Decls); diff --git a/gcc/ada/par-ch5.adb b/gcc/ada/par-ch5.adb index f66d77314f32..053b6d7ca167 100644 --- a/gcc/ada/par-ch5.adb +++ b/gcc/ada/par-ch5.adb @@ -497,8 +497,6 @@ package body Ch5 is -- Cases of statements starting with an identifier when Tok_Identifier => - Check_Bad_Layout; - -- Save scan pointers and line number in case block label Id_Node := Token_Node; @@ -802,6 +800,8 @@ package body Ch5 is end if; end if; + Check_Bad_Layout_At (Scan_State_Label); + -- Statement starting with operator symbol. This could be -- a call, a name starting an assignment, or a qualified -- expression. diff --git a/gcc/ada/par-util.adb b/gcc/ada/par-util.adb index 790d238696c6..e5ee0fb88997 100644 --- a/gcc/ada/par-util.adb +++ b/gcc/ada/par-util.adb @@ -197,6 +197,19 @@ package body Util is end if; end Check_Bad_Layout; + ------------------------- + -- Check_Bad_Layout_At -- + ------------------------- + + procedure Check_Bad_Layout_At (Scan_State : Saved_Scan_State) is + S : Saved_Scan_State; + begin + Save_Scan_State (S); + Restore_Scan_State (Scan_State); + Check_Bad_Layout; + Restore_Scan_State (S); + end Check_Bad_Layout_At; + -------------------------- -- Check_Future_Keyword -- -------------------------- diff --git a/gcc/ada/par.adb b/gcc/ada/par.adb index 4fe825b57af2..53966bc4c77c 100644 --- a/gcc/ada/par.adb +++ b/gcc/ada/par.adb @@ -1324,6 +1324,9 @@ function Par (Configuration_Pragmas : Boolean) return List_Id is -- is exdented from the current expected end column, and if so an -- error message is generated. + procedure Check_Bad_Layout_At (Scan_State : Saved_Scan_State); + -- Same as Check_Bad_Layout with Scan_State as the current scan state + procedure Check_Misspelling_Of (T : Token_Type); pragma Inline (Check_Misspelling_Of); -- This is similar to the function above, except that it does not
