Skip to content

Commit ab491b3

Browse files
committed
Various <meta> implementation improvements [GH #330]
1 parent 970f36b commit ab491b3

38 files changed

Lines changed: 1208 additions & 100 deletions

‎src/class_decl.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21533,11 +21533,12 @@ be entered.
2153321533
/* Copy the type (which may have been changed by apply_bit_field_size) into
2153421534
the field entry. */
2153521535
field->type = member_type;
21536-
/* For an unnamed bit field, do not create the field symbol. */
21536+
/* For an unnamed bit field, create an unnamed field symbol that is not
21537+
entered in the symbol table. */
2153721538
if (unnamed_field && decl_info->is_bit_field) {
21538-
/* All field entries for an unnamed bit field share the same symbol. It is
21539-
used for easy identification. */
21540-
field->source_corresp.assoc_info = (char *)get_unnamed_field_symbol();
21539+
member_sym = make_unnamed_field_symbol(&locator->source_position);
21540+
member_sym->variant.field.ptr = field;
21541+
field->source_corresp.assoc_info = (char *)member_sym;
2154121542
/* Update the source correspondence information manually -- there's no
2154221543
symbol. */
2154321544
field->source_corresp.decl_position = locator->source_position;
@@ -21633,7 +21634,9 @@ be entered.
2163321634
/* Fields of closure types may be declared "on the fly" (in the case of
2163421635
implicit captures), and are not subject to pragmas in any case.
2163521636
However, we do want to record the declaration of init-capture fields. */
21636-
} else if (member_sym != NULL && !decl_info->is_anonymous_union) {
21637+
} else if (member_sym != NULL && !decl_info->is_anonymous_union &&
21638+
!is_unnamed_field_symbol(member_sym)) {
21639+
/* (The declaration of an unnamed bit-field was recorded above.) */
2163721640
record_symbol_declaration(SRK_DECLARATION | SRK_DEFINITION, member_sym,
2163821641
&locator->source_position,
2163921642
decl_state->source_sequence_entry);

‎src/decl_inits.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9201,7 +9201,7 @@ non-NULL, set *end_of_list to the last initializer in the list.
92019201
} /* if */
92029202
} else if (!field->compiler_generated) {
92039203
a_symbol_ptr sym = symbol_for(field);
9204-
if (sym == NULL || sym->is_error || sym == get_unnamed_field_symbol()) {
9204+
if (sym == NULL || sym->is_error || is_unnamed_field_symbol(sym)) {
92059205
/* Skip over any error and unnamed fields. */
92069206
continue;
92079207
} /* if */

‎src/decl_spec.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7207,6 +7207,7 @@ template. dsi_flags is the set of input flags passed to decl_specifiers.
72077207
} else if (is_definition) {
72087208
/* An unnamed enum type. mark_defined can't be called to record the
72097209
declaration, so the subroutines that do so are called directly. */
7210+
set_decl_sequence_number(tag_sym);
72107211
#if MAINTAIN_CLASS_MEMBER_LIST
72117212
record_class_member_declaration((char*)enum_type, iek_type);
72127213
#endif /* MAINTAIN_CLASS_MEMBER_LIST */

‎src/decls.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2834,10 +2834,11 @@ is invalid. Also promote the fields of the union type to the current scope.
28342834
/* Promote the fields of the anonymous union to the current scope, and do
28352835
some error checking on the anonymous union's members. */
28362836
assoc_object_sym = make_anonymous_parent_object_symbol(
2837-
(a_symbol_kind)sk_variable,
2837+
sk_variable,
28382838
&pos_curr_token,
28392839
scope_stack[decl_scope_level].number);
28402840
assoc_object_sym->variant.variable.ptr = vp;
2841+
vp->source_corresp.assoc_info = (char*)assoc_object_sym;
28412842
if (at_file_or_namespace_scope) {
28422843
set_namespace_membership(assoc_object_sym, &vp->source_corresp,
28432844
(a_namespace_ptr)NULL);

‎src/expr.c‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10841,6 +10841,7 @@ a left parenthesis in the source.
1084110841
{
1084210842
locator->source_position = eriep->saved_operand.position;
1084310843
} /* if */
10844+
locator->is_splicer = eriep->saved_operand.designated_by_splice;
1084410845
/* For a qualified id case, make sure the id is a member of the class
1084510846
or one of its base classes. */
1084610847
if (need_member_sym_check && !*err && is_qualified) {
@@ -11553,7 +11554,8 @@ case).
1155311554
operand_1, is_arrow_operator, member_sym,
1155411555
projection_member_sym,
1155511556
(a_boolean)locator.access_control_error_reported,
11556-
/*do_protected_member_check=*/TRUE, &member_position);
11557+
/*do_protected_member_check=*/!locator.is_splicer,
11558+
&member_position);
1155711559
do_field_selection_operation(operand_1, orig_class_struct_union_type,
1155811560
is_arrow_operator,
1155911561
/*compiler_generated=*/FALSE,
@@ -11629,7 +11631,7 @@ case).
1162911631
error_and_make_error_operand(ec_expr_not_constant, result);
1163011632
} else {
1163111633
if (!force_indefinite_function &&
11632-
member_sym->kind == (a_symbol_kind)sk_member_function) {
11634+
symbol_is(member_sym, sk_member_function)) {
1163311635
/* For a simple non-overloaded function, adjust the selector
1163411636
to the proper class. We don't do this for the
1163511637
cases that go through overload resolution, since that
@@ -11639,15 +11641,16 @@ case).
1163911641
is_arrow_operator,
1164011642
member_sym,
1164111643
projection_member_sym,
11642-
(a_boolean)locator.
11643-
access_control_error_reported,
11644-
/*do_protected_member_check=*/TRUE,
11644+
(a_boolean)locator
11645+
.access_control_error_reported,
11646+
/*do_protected_member_check=*/
11647+
!locator.is_splicer,
1164511648
&member_position);
1164611649
} /* if */
1164711650
/* Make an operand for the function with the selector bound
1164811651
to it. */
11649-
if (member_sym->kind == (a_symbol_kind)sk_overloaded_function ||
11650-
member_sym->kind == (a_symbol_kind)sk_function_template ||
11652+
if (symbol_is(member_sym, sk_overloaded_function) ||
11653+
symbol_is(member_sym, sk_function_template) ||
1165111654
force_indefinite_function) {
1165211655
/* Overloaded function or member template. */
1165311656
make_indefinite_function_operand(projection_member_sym,
@@ -11672,7 +11675,7 @@ case).
1167211675
&end_position),
1167311676
rep,
1167411677
result);
11675-
set_operand_name_reference_from_locator(result, &locator);
11678+
set_operand_id_details_from_locator(result, &locator);
1167611679
} /* if */
1167711680
copy_operand(operand_1, bound_function_selector) /*lint !e413*/;
1167811681
bind_member_function_operand_to_selector(bound_function_selector,
@@ -11690,7 +11693,7 @@ case).
1169011693
&end_position),
1169111694
rep,
1169211695
result);
11693-
set_operand_name_reference_from_locator(result, &locator);
11696+
set_operand_id_details_from_locator(result, &locator);
1169411697
treat_as_static_member:
1169511698
result->is_name_followed_by_left_paren =
1169611699
member_name_followed_by_left_paren;
@@ -41914,6 +41917,7 @@ FIXME: This is currently incomplete.
4191441917
(a_ref_entry*)NULL,
4191541918
result);
4191641919
result->is_id_expression = TRUE;
41920+
result->designated_by_splice = TRUE;
4191741921
} else if (iek == iek_variable) {
4191841922
vp = (a_variable*)rvp->entity.ptr;
4191941923
variable_case:
@@ -41936,6 +41940,7 @@ FIXME: This is currently incomplete.
4193641940
(a_ref_entry*)NULL,
4193741941
result);
4193841942
result->is_id_expression = TRUE;
41943+
result->designated_by_splice = TRUE;
4193941944
} else {
4194041945
make_function_designator_operand(symbol_for(rp),
4194141946
/*is_qualified_name=*/FALSE,

‎src/exprutil.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3489,6 +3489,7 @@ values.
34893489
operand->is_qualified_name = FALSE;
34903490
operand->is_microsoft_deferred_name = FALSE;
34913491
operand->access_control_error_reported = FALSE;
3492+
operand->designated_by_splice = FALSE;
34923493
operand->is_operand_of_address_of = FALSE;
34933494
operand->has_required_ptr_to_member_form = FALSE;
34943495
operand->is_template_id = FALSE;
@@ -6344,10 +6345,11 @@ This includes in particular name reference information.
63446345
{
63456346
set_operand_name_reference_from_locator(operand, locator);
63466347
operand->is_qualified_name = locator->is_qualified_name;
6347-
if (operand->kind == (an_operand_kind)ok_indefinite_function ||
6348-
operand->kind == (an_operand_kind)ok_undefined_symbol
6348+
operand->designated_by_splice = locator->is_splicer;
6349+
if (is_indefinite_function_operand(operand) ||
6350+
is_undefined_symbol_operand(operand)
63496351
#if MICROSOFT_EXTENSIONS_ALLOWED
6350-
|| operand->kind == (an_operand_kind)ok_property_ref
6352+
|| is_property_ref_operand(operand)
63516353
#endif /* MICROSOFT_EXTENSIONS_ALLOWED */
63526354
) {
63536355
operand->id_position = locator->source_position;
@@ -7422,6 +7424,7 @@ destroyed its source position, etc. Restore such things from
74227424
orig_operand->selector_is_object_pointer;
74237425
operand->virtual_function = orig_operand->virtual_function;
74247426
operand->is_qualified_name = orig_operand->is_qualified_name;
7427+
operand->designated_by_splice = orig_operand->designated_by_splice;
74257428
operand->access_control_error_reported =
74267429
orig_operand->access_control_error_reported;
74277430
operand->is_operand_of_address_of =
@@ -23641,7 +23644,7 @@ by an "&" in the source, and *ampersand_position gives its position.
2364123644
{
2364223645
an_operand orig_operand;
2364323646
a_symbol_ptr member_sym, fund_sym;
23644-
a_boolean has_required_ampersand;
23647+
a_boolean has_required_ampersand, check_protected_access;
2364523648
a_boolean allow_addr_of_managed_member = FALSE, force_node = FALSE;
2364623649

2364723650
has_required_ampersand = (ampersand_position != NULL &&
@@ -23669,11 +23672,15 @@ by an "&" in the source, and *ampersand_position gives its position.
2366923672
#if MICROSOFT_EXTENSIONS_ALLOWED
2367023673
allow_addr_of_managed_member = operand->allow_addr_of_managed_member;
2367123674
#endif /* MICROSOFT_EXTENSIONS_ALLOWED */
23675+
/* The protected member access check does not apply to a member designated
23676+
by a splice-expression (N5046 [class.protected]). */
23677+
check_protected_access = !operand->access_control_error_reported &&
23678+
!operand->designated_by_splice;
2367223679
/* Make an operand for a pointer-to-member constant. */
2367323680
make_ptr_to_member_constant_operand(member_sym, member_sym,
2367423681
&orig_operand.position,
2367523682
end_position_of_operand(&orig_operand),
23676-
!operand->access_control_error_reported,
23683+
check_protected_access,
2367723684
(a_boolean)operand->is_qualified_name,
2367823685
has_required_ampersand,
2367923686
allow_addr_of_managed_member,

‎src/exprutil.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,15 @@ typedef struct an_operand {
364364
essentially still just a representation for
365365
an identifier, e.g., ok_indefinite_function and
366366
ok_sym_for_member. */
367+
a_bit_field designated_by_splice:1;
368+
/* TRUE if this operand was generated from a
369+
splice-expression designating a class member.
370+
Such a member is accessible from any point, and
371+
the additional protected member access check
372+
(N5046 [class.protected]) does not apply to it.
373+
Like access_control_error_reported, this
374+
remains meaningful only for ok_sym_for_member
375+
operands. */
367376
a_bit_field is_operand_of_address_of:1;
368377
/* TRUE if this operand is the immediate operand
369378
of an "&" address-of operator. This is

‎src/folding.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9058,7 +9058,8 @@ architectures for which these assumptions are not valid.
90589058
} else if (!type_is(type, tk_union) &&
90599059
field->is_bit_field && field->bit_size != 0 &&
90609060
unnamed_bit_field_is_padding() &&
9061-
symbol_for(field) == get_unnamed_field_symbol()) {
9061+
symbol_for(field) != NULL &&
9062+
is_unnamed_field_symbol(symbol_for(field))) {
90629063
/* An unnamed bit-field of non-zero width is padding. (In a
90639064
union, an unnamed bit-field overlaps the other members, so
90649065
it is handled by the size test above instead.) */

0 commit comments

Comments
 (0)