Skip to content

Commit 60e9e97

Browse files
NinaRannsiains
authored andcommitted
work in progress
1 parent 9b4ac8a commit 60e9e97

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

gcc/c-family/c-common.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ const struct c_common_resword c_common_reswords[] =
516516
{ "constinit", RID_CONSTINIT, D_CXXONLY | D_CXX20 | D_CXXWARN },
517517
{ "const_cast", RID_CONSTCAST, D_CXXONLY | D_CXXWARN },
518518
{ "continue", RID_CONTINUE, 0 },
519-
{ "contract_assert", RID_CONTASSERT, D_CXXONLY | D_CXXWARN }, // removed D_CXX20 in order for contracts to work out of the box
520519
{ "decltype", RID_DECLTYPE, D_CXXONLY | D_CXX11 | D_CXXWARN },
521520
{ "default", RID_DEFAULT, 0 },
522521
{ "delete", RID_DELETE, D_CXXONLY | D_CXXWARN },
@@ -599,6 +598,10 @@ const struct c_common_resword c_common_reswords[] =
599598
{ "co_yield", RID_CO_YIELD, D_CXX_COROUTINES_FLAGS | D_CXXWARN },
600599
{ "co_return", RID_CO_RETURN, D_CXX_COROUTINES_FLAGS | D_CXXWARN },
601600

601+
/* Contracts-related keywords */
602+
{ "contract_assert", RID_CONTASSERT, D_CXXONLY | D_CXXWARN }, // removed D_CXX20 in order for contracts to work out of the box
603+
{ "inherited", RID_INHERITED, D_CXXONLY | D_CXXWARN },
604+
602605
/* These Objective-C keywords are recognized only immediately after
603606
an '@'. */
604607
{ "compatibility_alias", RID_AT_ALIAS, D_OBJC },

gcc/c-family/c-common.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ enum rid
176176
RID_CONSTEXPR, RID_DECLTYPE, RID_NOEXCEPT, RID_NULLPTR, RID_STATIC_ASSERT,
177177

178178
/* C++20 */
179-
RID_CONSTINIT, RID_CONSTEVAL, RID_CONTASSERT,
179+
RID_CONSTINIT, RID_CONSTEVAL,
180180

181181
/* char8_t */
182182
RID_CHAR8,
@@ -190,6 +190,9 @@ enum rid
190190
/* C++ coroutines */
191191
RID_CO_AWAIT, RID_CO_YIELD, RID_CO_RETURN,
192192

193+
/* C++ contracts */
194+
RID_CONTASSERT, RID_INHERITED,
195+
193196
/* C++ transactional memory. */
194197
RID_ATOMIC_NOEXCEPT, RID_ATOMIC_CANCEL, RID_SYNCHRONIZED,
195198

gcc/cp/parser.cc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31861,6 +31861,51 @@ cp_parser_should_constify_contract (const contract_modifier& modifier)
3186131861
return should_constify;
3186231862
}
3186331863

31864+
/* Parse an inherited contract. */
31865+
31866+
static tree
31867+
cp_parse_inherited_contract (cp_parser *parser)
31868+
{
31869+
cp_token *token = cp_lexer_consume_token (parser->lexer);
31870+
location_t loc = token->location;
31871+
31872+
gcc_checking_assert(token->type == CPP_KEYWORD
31873+
&& token->keyword == RID_INHERITED);
31874+
31875+
matching_parens parens;
31876+
parens.require_open (parser);
31877+
31878+
if (flag_contracts_on_virtual_functions != CONTRACTS_ON_VIRTUALS_P3653)
31879+
{
31880+
error_at (loc, "inherited contracts are only available with"
31881+
" %<-fcontracts-on-virtual-functions=P3653%>");
31882+
31883+
cp_parser_skip_to_closing_parenthesis_1 (parser, /*recovering=*/true,
31884+
CPP_CLOSE_PAREN,
31885+
/*consume_paren=*/true);
31886+
return error_mark_node;
31887+
}
31888+
31889+
/* Otherwise, look for the class-name. */
31890+
tree type = cp_parser_class_name (parser,
31891+
/*typename_keyword_p=*/true,
31892+
/*template_keyword_p=*/false,
31893+
none_type,
31894+
/*check_dependency_p=*/false,
31895+
/*class_head_p=*/false,
31896+
/*is_declaration=*/false);
31897+
type = TREE_TYPE (type);
31898+
/* ": T...[constant-expression]" is a C++26 pack-index-specifier. */
31899+
if (cp_parser_next_tokens_are_pack_index_p (parser))
31900+
type = cp_parser_pack_index (parser, type);
31901+
31902+
cp_parser_skip_to_closing_parenthesis_1 (parser,
31903+
/*recovering=*/true,
31904+
CPP_CLOSE_PAREN,
31905+
/*consume_paren=*/true);
31906+
return error_mark_node;
31907+
}
31908+
3186431909
/* Parse a natural syntax contract specifier seq.
3186531910

3186631911
function-contract-specifier :
@@ -31901,6 +31946,11 @@ cp_parser_function_contract_specifier (cp_parser *parser)
3190131946
location_t loc = token->location;
3190231947
bool postcondition_p = is_attribute_p ("post", contract_name);
3190331948

31949+
token = cp_lexer_peek_token (parser->lexer);
31950+
31951+
if (token->type == CPP_KEYWORD && token->keyword == RID_INHERITED)
31952+
return cp_parse_inherited_contract(parser);
31953+
3190431954
/* Parse experimental modifiers on C++26 contracts. */
3190531955
contract_modifier modifier
3190631956
= cp_parser_function_contract_modifier_opt (parser);

0 commit comments

Comments
 (0)