In pragma Contract_Cases argument only "CASE_GUARD => CONSEQUENCE"
clauses are allowed. Once we know that the pragma argument is an
N_Aggregate, we checked if it has component associations; now we also
check that it has no expressions.
Same for the argument of the Subprogram_Variant contract, whose
implementation was heavily inspired by the Contract_Cases contract.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* contracts.adb (Analyze_Entry_Or_Subprogram_Contract,
Analyze_Subprogram_Body_Stub_Contract): Fix missing references
to Subprogram_Variant where similar references to Contract_Cases
are present.
* sem_prag.adb (Analyze_Contract_Case, Analyze_Variant): Check
that aggregate parameter has no expressions.
(Analyze_Pragma): Replace Contract_Cases with Subprogram_Variant
in a copy-pasted comment.
diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -668,7 +668,7 @@ package body Contracts is
end;
end if;
- -- Analyze contract-cases and test-cases
+ -- Analyze contract-cases, subprogram-variant and test-cases
Prag := Contract_Test_Cases (Items);
while Present (Prag) loop
@@ -1432,6 +1432,7 @@ package body Contracts is
-- Global
-- Postcondition
-- Precondition
+ -- Subprogram_Variant
-- Test_Case
else
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -549,7 +549,11 @@ package body Sem_Prag is
pragma Assert (Nkind (CCases) = N_Aggregate);
- if Present (Component_Associations (CCases)) then
+ -- Only CASE_GUARD => CONSEQUENCE clauses are allowed
+
+ if Present (Component_Associations (CCases))
+ and then No (Expressions (CCases))
+ then
-- Ensure that the formal parameters are visible when analyzing all
-- clauses. This falls out of the general rule of aspects pertaining
@@ -23900,7 +23904,7 @@ package body Sem_Prag is
Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
-- Chain the pragma on the contract for further processing by
- -- Analyze_Contract_Cases_In_Decl_Part.
+ -- Analyze_Subprogram_Variant_In_Decl_Part.
Add_Contract_Item (N, Defining_Entity (Subp_Decl));
@@ -29048,7 +29052,11 @@ package body Sem_Prag is
pragma Assert (Nkind (Variants) = N_Aggregate);
- if Present (Component_Associations (Variants)) then
+ -- Only "change_direction => discrete_expression" clauses are allowed
+
+ if Present (Component_Associations (Variants))
+ and then No (Expressions (Variants))
+ then
-- Ensure that the formal parameters are visible when analyzing all
-- clauses. This falls out of the general rule of aspects pertaining