itanium-cxx-abi / cxx-abi

C++ ABI Summary
504 stars 94 forks source link

Missing referenced type named "C" in section 2.2, "POD Data Types" #190

Open tahonermann opened 2 months ago

tahonermann commented 2 months ago

Section 2.2 "POD Data Types" states:

A member pointer type is treated exactly as if it were the C type described below.

The "described below" link references section 2.3, "Member Pointers". That section does not contain any prose but it does have two subsections, section 2.3.1, "Data Member Pointers" and section 2.3.2, Member Function Pointers", neither of which defines a type named "C".

Section 2.4, "Non-POD Class Types" uses the name "C" as a generic identifier for a class type. If this is the type intended by the "C type" reference, then the "described below" link should be updated to reference this section. I don't see an obvious way in which the "C" type described there fits with the "member pointer type is treated exactly as if it were the C type" wording though, so it seems that some other elucidation is still required.

jensmaurer commented 2 months ago

My guess is that "C type" refers to this C-style type definition presented further below:

struct {
    fnptr_t ptr;
    ptrdiff_t adj;
  };
tahonermann commented 2 months ago

Thanks, Jens. That seems likely. There would still be a gap for pointers to data members though.

jensmaurer commented 2 months ago

A pointer to data member is explained to be an offset stored in a ptrdiff_t.

tahonermann commented 2 months ago

Indeed, but the "A member pointer type is treated exactly as if it were the C type described below" wording doesn't differentiate between data members and member functions. It seems that "the C type described below" must be intended to refer to different parts of the prose; for pointers to data members, the C type is ptrdiff_t where as for pointers to member functions, the C type is the unnamed struct type below.

In 2.3.1 Data Member Pointers:

The basic ABI properties of data member pointer types are those of ptrdiff_t.

In 2.3.2 Member Function Pointers:

In all representations, the basic ABI properties of member function pointer types are those of the following class, where fnptr_t is the appropriate function-pointer type for a member function of this type:

  struct {
    fnptr_t ptr;
    ptrdiff_t adj;
  };

This would make sense as the intent. I think the wording can still be improved though.

rjmccall commented 2 months ago

That is the intent, yes. I'm open to suggestions about how to improve the wording.

zygoloid commented 1 month ago

Maybe just remove the "C":

A member pointer type is treated exactly as if it were the C type described below.

tahonermann commented 1 month ago

Maybe just remove the "C":

That helps, but there are two types to choose from (for data members vs member functions). Perhaps:

A member pointer type is treated exactly as if it were one of the C types described below.