The compiler reports a spurious error indicating that a subprogram with
aspect No_Return doesn't satisfy that aspect in cases where the subprogram
has formals whose type specifies a Type_Invariant aspect. The need for
invariant or postcondition checks leads to the creation of a nested
subprogram that wraps the enclosing subprogram's statements and exception
handler, defeating the checking that's done in Sem_Ch6.Check_Returns.
The fix is to suppress generation of the _wrapped_statements subprogram,
which is legitimate because the invariants and postconditions will not be
executed in any case for a No_Return subprogram since they can never be
reached.
gcc/ada/ChangeLog:
* contracts.adb (Expand_Subprogram_Contract): Don't call
Build_Subprogram_Contract_Wrapper for a No_Return subprogram,
but include any prologue declarations (such as for preconditions).
-- Step 6: Construct subprogram _wrapped_statements
-- When no statements are present we still need to insert contract
- -- related declarations.
+ -- related declarations. There's also no need to create the contracts
+ -- wrapper when the subprogram is marked as not returning, since
+ -- postconditions and invariant checks won't be reached in that case.
- if No (Stmts) then
+ if No (Stmts) or else No_Return (Subp_Id) then
Prepend_List_To (Declarations (Body_Decl), Decls);
- -- Otherwise, we need a wrapper
-
else
Build_Subprogram_Contract_Wrapper (Body_Id, Stmts, Decls, Result);
end if;