@@ -2769,6 +2769,33 @@ start_function_contracts (tree decl1)
2769
2769
if (!handle_contracts_p (decl1))
2770
2770
return ;
2771
2771
2772
+ /* Check that the user did not try to shadow a function parameter with the
2773
+ specified postcondition result name. */
2774
+ if (flag_contracts_nonattr)
2775
+ for (tree ca = DECL_CONTRACTS (decl1); ca; ca = CONTRACT_CHAIN (ca))
2776
+ if (POSTCONDITION_P (CONTRACT_STATEMENT (ca)))
2777
+ if (tree id = POSTCONDITION_IDENTIFIER (CONTRACT_STATEMENT (ca)))
2778
+ {
2779
+ if (TREE_CODE (id) == PARM_DECL)
2780
+ id = DECL_NAME (id);
2781
+ gcc_checking_assert (id && TREE_CODE (id) == IDENTIFIER_NODE);
2782
+ tree seen = lookup_name (id);
2783
+ if (seen
2784
+ && TREE_CODE (seen) == PARM_DECL
2785
+ && DECL_CONTEXT (seen)
2786
+ && DECL_CONTEXT (seen) == decl1)
2787
+ {
2788
+ auto_diagnostic_group d;
2789
+ error_at (EXPR_LOCATION (CONTRACT_STATEMENT (ca)),
2790
+ " contract postcondition result names must not shadow"
2791
+ " function parameters" );
2792
+ inform (DECL_SOURCE_LOCATION (seen), " parameter declared here" );
2793
+ POSTCONDITION_IDENTIFIER (CONTRACT_STATEMENT (ca))
2794
+ = error_mark_node;
2795
+ CONTRACT_CONDITION (CONTRACT_STATEMENT (ca)) = error_mark_node;
2796
+ }
2797
+ }
2798
+
2772
2799
/* For cdtors, we evaluate the contracts check inline. */
2773
2800
if (!outline_contracts_p (decl1))
2774
2801
return ;
@@ -2778,7 +2805,6 @@ start_function_contracts (tree decl1)
2778
2805
/* Do we already have declarations generated ? */
2779
2806
if (!DECL_PRE_FN (decl1) && !DECL_POST_FN (decl1))
2780
2807
build_contract_function_decls (decl1);
2781
-
2782
2808
}
2783
2809
2784
2810
/* If we have a precondition function and it's valid, call it. */
0 commit comments