===================================================================
@@ -2187,13 +2187,18 @@
("aspect % requires ''Class for null procedure");
-- Pre/postconditions are legal on a subprogram body if it is not
- -- a completion of a declaration.
+ -- a completion of a declaration. They are also legal on a stub
+ -- with no previous declarations (this is checked when processing
+ -- the corresponding aspects).
elsif Nkind (PO) = N_Subprogram_Body
and then Acts_As_Spec (PO)
then
null;
+ elsif Nkind (PO) = N_Subprogram_Body_Stub then
+ null;
+
elsif not Nkind_In (PO, N_Subprogram_Declaration,
N_Expression_Function,
N_Generic_Subprogram_Declaration,
===================================================================
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
+-- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -684,6 +684,15 @@
Stub_Node :=
New_Node (N_Subprogram_Body_Stub, Sloc (Specification_Node));
Set_Specification (Stub_Node, Specification_Node);
+
+ -- The specification has been parsed as part of a subprogram
+ -- declaration, and aspects have already been collected.
+
+ if Is_Non_Empty_List (Aspects) then
+ Set_Parent (Aspects, Stub_Node);
+ Set_Aspect_Specifications (Stub_Node, Aspects);
+ end if;
+
Scan; -- past SEPARATE
Pop_Scope_Stack;
TF_Semicolon;
===================================================================
@@ -220,6 +220,7 @@
N_Subprogram_Body => True,
N_Subprogram_Declaration => True,
N_Subprogram_Renaming_Declaration => True,
+ N_Subprogram_Body_Stub => True,
N_Subtype_Declaration => True,
N_Task_Body => True,
N_Task_Type_Declaration => True,
===================================================================
@@ -2681,10 +2681,11 @@
end if;
-- Ada 2012 aspects may appear in a subprogram body, but only if there
- -- is no previous spec.
+ -- is no previous spec. Ditto for a subprogram stub that does not have
+ -- a corresponding spec, but for which there may also be a spec_id.
if Has_Aspects (N) then
- if Present (Corresponding_Spec (N)) then
+ if Present (Spec_Id) then
Error_Msg_N
("aspect specifications must appear in subprogram declaration",
N);
===================================================================
@@ -1693,6 +1693,14 @@
else
Insert_After (N, Aitem);
+
+ -- Pre/Postconditions on stubs are analyzed at once,
+ -- because the proper body is analyzed next, and the
+ -- contract must be captured before the body.
+
+ if Nkind (N) = N_Subprogram_Body_Stub then
+ Analyze (Aitem);
+ end if;
end if;
goto Continue;