Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[class.prop] standard-layout class type requirements are hard to read #7593

Open
Eisenwave opened this issue Jan 28, 2025 · 3 comments
Open

Comments

@Eisenwave
Copy link
Contributor

I find that https://eel.is/c++draft/class.prop#2.7 is pretty hard to read in its current state:

draft/source/classes.tex

Lines 208 to 230 in 0ca05d2

\begin{itemize}
\item If \tcode{X} is a non-union class type with no non-static data members,
the set $M(\mathtt{X})$ is empty.
\item If \tcode{X} is a non-union class type with a non-static data
member of type $\mathtt{X}_0$
that is either of zero size or
is the first non-static data member of \tcode{X}
(where said member may be an anonymous union),
the set $M(\mathtt{X})$ consists of $\mathtt{X}_0$ and the elements of
$M(\mathtt{X}_0)$.
\item If \tcode{X} is a union type, the set $M(\mathtt{X})$ is
the union of all $M(\mathtt{U}_i)$ and the set containing all $\mathtt{U}_i$,
where each $\mathtt{U}_i$ is the type of the $i^\text{th}$ non-static data member
of \tcode{X}.
\item If \tcode{X} is an array type with element type $\mathtt{X}_e$,
the set $M(\mathtt{X})$ consists of $\mathtt{X}_e$
and the elements of $M(\mathtt{X}_e)$.
\item If \tcode{X} is a non-class, non-array type, the set $M(\mathtt{X})$ is empty.
\end{itemize}

For starters, we can replace the first and last bullet like:

-\item If \tcode{X} is a non-union class type with no non-static data members, 
-the set $M(\mathtt{X})$ is empty. 
 [...]
-\item If \tcode{X} is a non-class, non-array type, the set $M(\mathtt{X})$ is empty.
+Otherwise, the set $M(\mathtt{X})$ is empty.

I may draft up an actual PR for this soon, but I'm still pondering on how to fully simplify this.

@Eisenwave
Copy link
Contributor Author

Another optimization opportunity:

-has no element of the set M(S) of types as a base class
+has no base class in the set M(S) of types

@Eisenwave
Copy link
Contributor Author

It may also be helpful to simply use a good name for M(X) rather than having a note explain the intent. Something like

has none if its zero-offset types as a base class, where the zero-offset types of a type X are defined as follows:

Then we could also delete https://eel.is/c++draft/class.prop#note-1

@Eisenwave
Copy link
Contributor Author

Lénárd Szolnoki noted that CWG2736 is making changes in the same area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant