Skip to content

Commit ff7cbc9

Browse files
committed
c++, contracts: Handle more of P2900 3.4.3 Part 1.
This handles a diagnostic when postconditions are applied to a function declaration that is not a definition.
1 parent d1d1b3a commit ff7cbc9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

gcc/cp/decl.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5982,6 +5982,21 @@ start_decl (const cp_declarator *declarator,
59825982
return error_mark_node;
59835983
}
59845984

5985+
if (flag_contracts_nonattr
5986+
&& TREE_CODE (decl) == FUNCTION_DECL
5987+
&& !processing_template_decl
5988+
&& DECL_RESULT (decl)
5989+
&& is_auto (TREE_TYPE (DECL_RESULT (decl))))
5990+
for (tree contract = DECL_CONTRACTS (decl); contract;
5991+
contract = CONTRACT_CHAIN (contract))
5992+
if (POSTCONDITION_P (CONTRACT_STATEMENT (contract))
5993+
&& POSTCONDITION_IDENTIFIER (CONTRACT_STATEMENT (contract)))
5994+
{
5995+
error_at (DECL_SOURCE_LOCATION (decl),
5996+
"postconditions with deduced result name types must only"
5997+
" appear on function definitions");
5998+
return error_mark_node;
5999+
}
59856000
/* Save the DECL_INITIAL value in case it gets clobbered to assist
59866001
with attribute validation. */
59876002
initial = DECL_INITIAL (decl);

0 commit comments

Comments
 (0)