* [Ada] Enable Error_Msg_GNAT_Extension for mixed decl/stmts
@ 2022-09-05 7:26 Marc Poulhiès
0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2022-09-05 7:26 UTC (permalink / raw)
To: gcc-patches; +Cc: Bob Duff
[-- Attachment #1: Type: text/plain, Size: 602 bytes --]
Enable mixing of declarative items and statements under
the -gnatX switch. The previous version used the -gnat2022
switch.
In addition, change the error message so that it advertises
the new feature when it is disabled. Instead of:
declarations must come before "begin"
we now say (without -gnatX):
declarations mixed with statements is a GNAT-specific extension
unit must be compiled with -gnatX or use pragma Extensions_Allowed (On)
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* par-ch5.adb
(P_Sequence_Of_Statements): Call Error_Msg_GNAT_Extension to give
the error message.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2201 bytes --]
diff --git a/gcc/ada/par-ch5.adb b/gcc/ada/par-ch5.adb
--- a/gcc/ada/par-ch5.adb
+++ b/gcc/ada/par-ch5.adb
@@ -242,8 +242,8 @@ package body Ch5 is
-- In Ada 2022, we allow declarative items to be mixed with
-- statements. The loop below alternates between calling
- -- P_Declarative_Items to parse zero or more declarative items, and
- -- parsing a statement.
+ -- P_Declarative_Items to parse zero or more declarative items,
+ -- and parsing a statement.
loop
Ignore (Tok_Semicolon);
@@ -255,26 +255,17 @@ package body Ch5 is
(Statement_List, Declare_Expression => False,
In_Spec => False, In_Statements => True);
- -- Use the length of the list to determine whether we parsed any
- -- declarative items. If so, it's an error pre-2022. ???We should
- -- be calling Error_Msg_Ada_2022_Feature below, to advertise the
- -- new feature, but that causes a lot of test diffs, so for now,
- -- we mimic the old "...before begin" message.
+ -- Use the length of the list to determine whether we parsed
+ -- any declarative items. If so, it's an error unless language
+ -- extensions are enabled.
if List_Length (Statement_List) > Num_Statements then
if All_Errors_Mode or else No (Decl_Loc) then
Decl_Loc := Sloc (Pick (Statement_List, Num_Statements + 1));
- if False then
- Error_Msg_Ada_2022_Feature
- ("declarations mixed with statements",
- Sloc (Pick (Statement_List, Num_Statements + 1)));
- else
- if Ada_Version < Ada_2022 then
- Error_Msg
- ("declarations must come before BEGIN", Decl_Loc);
- end if;
- end if;
+ Error_Msg_GNAT_Extension
+ ("declarations mixed with statements",
+ Sloc (Pick (Statement_List, Num_Statements + 1)));
end if;
end if;
end;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-09-05 7:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05 7:26 [Ada] Enable Error_Msg_GNAT_Extension for mixed decl/stmts Marc Poulhiès
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).