cplusplus / cplusplus/draft

[basic.compound] p4 What the definition of whether two objects are the same CWG2606

Open
#5,356 18 comments 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

[expr.static.cast] p13 states

A prvalue of type “pointer to cv1 void” can be converted to a prvalue of type “pointer to cv2 T”, where T is an object type and cv2 is the same cv-qualification as, or greater cv-qualification than, cv1. ... Otherwise, if the original pointer value points to an object a, and there is an object b of type T (ignoring cv-qualification) that is pointer-interconvertible with a, the result is a pointer to b. Otherwise, the pointer value is unchanged by the conversion.

[basic.compound] p4.1 states

Two objects a and b are pointer-interconvertible if:

  • they are the same object, or
  • [...]

Consider this example:

int const v = 0;
void const* cvptr = &v;
void* vptr =  const_cast<void*>(cvptr);
int* iptr = static_cast<int*>(vptr );  // #3

The pointer value of vptr points to v as per [conv.ptr] p2, the result of const_cast<void*>(cvptr) refers to the original entity(the same pointer value as vptr's) as per [expr.const.cast] p3. After figuring out what vptr is, we can pay more attention to #3, which is the case specified in [expr.static.cast] p13 where the conversion is that converts a prvalue of "pointer to void" to a prvalue of type "pointer to int". In this case, the original pointer value points to v(which is object a, whose type is int const) while the expected object b is of type int. They have different types. So, the issue is whether two objects that have similar types but are not the same can be the same object? From the perspective of English, when we say two objects are the same, they should be identical in any respect at least.

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 by reading [basic.compound] p4.1, [conv.ptr] p2, [expr.const.cast] p3, and [expr.static.cast] p13 alongside the supplied example. Determine the exact ambiguity around cv-qualified objects and the #3 conversion, then propose wording that resolves it and validate the result against the cited rules.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.