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.cdtor.example] p1 The comment is wrong since the example violates [class.cdtor]p3 #5175

Open
xmh0511 opened this issue Dec 27, 2021 · 1 comment

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Dec 27, 2021

extern X xobj;
int* p3 = &xobj.i;                      // OK, X is a trivial class
X xobj;

Although the example does not violate [class.cdtor] p1, however, [class.cdtor] p3 says

To form a pointer to (or access the value of) a direct non-static member of an object obj, the construction of obj shall have started and its destruction shall not have completed, otherwise the computation of the pointer value (or accessing the member value) results in undefined behavior.

In this example, we do form a pointer to a direct non-static member(i) of an object xobj, and the construction of xobj have not started at the point of the second line, the above rule explicitly says that the computation of the pointer value results in UB. So, Is the comment wrong?

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Dec 30, 2021

IMO that the restrictions should be relaxed. I've sent a mail for this in order to submit a CWG issue. CWG1517 has already been opened for this.

Taking the address of a virtual base class subobject or its subobject before construction or after destruction should remain undefined, because the vptr is probably invalid. But in other cases, the behavior should be made well-defined.

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

2 participants