cplusplus / cplusplus/draft

[class.cdtor.example] p1 The comment is wrong since the example violates [class.cdtor]p3

Open
#5,175 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the class.cdtor.example excerpt and the cited [class.cdtor] paragraph in the draft. Resolve whether taking the member address is covered by the quoted rule, then update the example comment or related wording so it is consistent with the standard.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, tex
Domain
documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.