cplusplus / cplusplus/draft

[intro.object] Definition of "most derived object" does not match its use CWG 1517

Open
#2,950 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

According to [intro.object] p6, a most derived object is an object of a most derived class type or of a non-class type, however, almost all mentions of it in the standard use it as a property that relates two object to each other (Ex: A is the most derived object of B), while the definition currently just describes an object (Ex: A is a most derived object).

Examples of use:
[defns.dynamic.type] type of the most derived object to which the glvalue refers

In this definition, most derived object is used as if it relates two objects, which it doesn't. What this means is that "dynamic type" is undefined for an expression that refers to an object that is not a complete object. For instance, if you had a a reference to B, and you initialized it with an object of type D, where B is a base class of D, the reference would be bound to the base class subobject, rather than the object itself, so the dynamic type of an expression naming that reference would be undefined, according to the current definition.

[class.ctor] p5 Here, the wording alludes to "the most derived object", referring to some specific object, that has not been defined.

There are many such cases like these, and can be fixed by defining "most derived object" as a term that relates two objects like so:

The most derived object of an object B is determined as follows:

- If B is a complete object, member subobject, or array element, or, if B is of non-class type, the msot derived object of B is B
- Otherwise, the most derived object of B is the most derived object of the object containing B

Some rewording would be required for clauses that currently refer to most derived objects (they are incorrect even now), which I will submit in a pull request if this change is deemed good (I'm on vacation right now, so it will take about a week)

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 [intro.object] p6 and compare its definition with the uses in [defns.dynamic.type] and [class.ctor] cited in the issue. Review the other references to “most derived object”; done means the definition and dependent wording consistently express the intended relationship between objects.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.