Skip to content

Commit 3da4030

Browse files
NinaRannsiains
authored andcommitted
inherited in class
1 parent 0b40073 commit 3da4030

File tree

6 files changed

+237
-83
lines changed

6 files changed

+237
-83
lines changed

gcc/cp/class.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3232,7 +3232,7 @@ check_for_override (tree decl, tree ctype)
32323232
== CONTRACTS_ON_VIRTUALS_NONE)
32333233
{
32343234
error_at (DECL_SOURCE_LOCATION(decl),
3235-
"Contracts can not be added to virtual functions.");
3235+
"Contracts cannot be added to virtual functions.");
32363236
}
32373237
}
32383238
else if (DECL_FINAL_P (decl))

gcc/cp/contracts.cc

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,20 @@ extract_contract_attributes (tree fndecl)
980980
return contracts;
981981
}
982982

983+
/*
984+
*/
985+
986+
/* Set contracts of FNDECL to be CONTRACTS. */
987+
988+
void
989+
set_contract_attributes (tree fndecl, tree contracts)
990+
{
991+
remove_contract_attributes (fndecl);
992+
tree attrs = chainon (DECL_ATTRIBUTES(fndecl), contracts);
993+
DECL_ATTRIBUTES (fndecl) = attrs;
994+
}
995+
996+
983997
/* Copy contract attributes from NEWDECL onto the attribute list of
984998
OLDDECL. */
985999

@@ -3049,11 +3063,6 @@ maybe_apply_function_contracts (tree fndecl)
30493063
/* We should not have reached here with nothing to do... */
30503064
gcc_checking_assert (do_pre || do_post);
30513065

3052-
if (contract_any_deferred_p (DECL_CONTRACTS (fndecl)))
3053-
{
3054-
//debug_tree (DECL_CONTRACTS (fndecl));
3055-
}
3056-
30573066
/* If the function is noexcept, the user's written body will be wrapped in a
30583067
MUST_NOT_THROW expression. In that case we want to extract the body from
30593068
that and build the replacement (including the pre and post-conditions as
@@ -3126,16 +3135,18 @@ maybe_apply_function_contracts (tree fndecl)
31263135
If remap_post is false, postconditions are dropped from the destination. */
31273136

31283137
tree
3129-
remap_contracts (tree dest, tree source, bool remap_result = true,
3130-
bool remap_post = true )
3138+
copy_and_remap_contracts (tree dest, tree source, bool remap_result = true,
3139+
contract_match_kind remap_kind = cmk_all )
31313140
{
31323141
tree last = NULL_TREE, contract_attrs = NULL_TREE;
31333142
for (tree a = DECL_CONTRACTS (source);
31343143
a != NULL_TREE;
31353144
a = CONTRACT_CHAIN (a))
31363145
{
3137-
if (!remap_post
3138-
&& (TREE_CODE (CONTRACT_STATEMENT (a)) == POSTCONDITION_STMT))
3146+
if ((remap_kind == cmk_pre
3147+
&& (TREE_CODE (CONTRACT_STATEMENT (a)) == POSTCONDITION_STMT))
3148+
|| (remap_kind == cmk_post
3149+
&& (TREE_CODE (CONTRACT_STATEMENT (a)) == PRECONDITION_STMT)))
31393150
continue;
31403151

31413152
tree c = copy_node (a);
@@ -3535,18 +3546,19 @@ define_contract_wrapper_func (const tree& fndecl, const tree& wrapdecl, void*)
35353546
bool is_virtual = DECL_IOBJ_MEMBER_FUNCTION_P (fndecl)
35363547
&& DECL_VIRTUAL_P (fndecl);
35373548
/* We check postconditions on virtual function calls or if postcondition
3538-
checks are enabled for all clients. We should not get here unless there
3549+
checks are enabled for clients. We should not get here unless there
35393550
are some checks to make. */
35403551
bool check_post
35413552
= (flag_contract_nonattr_client_check > 1)
35423553
|| (is_virtual
35433554
&& (flag_contracts_on_virtual_functions
3544-
== CONTRACTS_ON_VIRTUALS_P2900R13));
3555+
!= CONTRACTS_ON_VIRTUALS_NONE));
35453556
/* For wrappers on CDTORs we need to refer to the original contracts,
35463557
when the wrapper is around a clone. */
35473558
set_decl_contracts( wrapdecl,
3548-
remap_contracts (wrapdecl, DECL_ORIGIN (fndecl),
3549-
/*remap_result*/true, check_post));
3559+
copy_and_remap_contracts (wrapdecl, DECL_ORIGIN (fndecl),
3560+
/*remap_result*/true,
3561+
check_post? cmk_all : cmk_pre));
35503562

35513563
start_preparsed_function (wrapdecl, /*DECL_ATTRIBUTES*/NULL_TREE,
35523564
SF_DEFAULT | SF_PRE_PARSED);

gcc/cp/contracts.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ enum contract_matching_context
218218
cmc_override
219219
};
220220

221+
enum contract_match_kind
222+
{
223+
cmk_all,
224+
cmk_pre,
225+
cmk_post
226+
};
227+
221228
/* True if NODE is any kind of contract. */
222229
#define CONTRACT_P(NODE) \
223230
(TREE_CODE (NODE) == ASSERTION_STMT \
@@ -349,7 +356,7 @@ extern tree finish_contract_attribute (tree, tree);
349356
extern tree invalidate_contract (tree);
350357
extern tree splice_out_contracts (tree);
351358
extern bool all_attributes_are_contracts_p (tree);
352-
extern tree remap_contracts (tree, tree, bool, bool);
359+
extern tree copy_and_remap_contracts (tree, tree, bool, contract_match_kind);
353360
extern void start_function_contracts (tree);
354361
extern void maybe_apply_function_contracts (tree);
355362
extern void finish_function_contracts (tree);

gcc/cp/cp-tree.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9020,6 +9020,7 @@ extern void check_param_in_redecl (tree, tree);
90209020
extern tree view_as_const (tree);
90219021
extern tree maybe_contract_wrap_call (tree, tree);
90229022
extern bool emit_contract_wrapper_func (bool);
9023+
extern void set_contract_attributes (tree, tree);
90239024

90249025
/* Return the first contract in ATTRS, or NULL_TREE if there are none. */
90259026

@@ -9074,6 +9075,22 @@ set_contract_const (tree t, bool constify)
90749075
TREE_LANG_FLAG_4 (CONTRACT_CHECK (t)) = constify;
90759076
}
90769077

9078+
/* Returns whether the contract is inherited. */
9079+
9080+
inline bool
9081+
get_contract_inherited (const_tree t)
9082+
{
9083+
return TREE_LANG_FLAG_5 (CONTRACT_CHECK (t));
9084+
}
9085+
9086+
/* Mark the contract as inherited */
9087+
9088+
inline void
9089+
set_contract_inherited (tree t, bool inherited)
9090+
{
9091+
TREE_LANG_FLAG_5 (CONTRACT_CHECK (t)) = inherited;
9092+
}
9093+
90779094
/* Test if EXP is a contract const wrapper node. */
90789095

90799096
inline bool

0 commit comments

Comments
 (0)