cplusplus / cplusplus/draft

[dcl.type.decltype] p1 What is the entity named by E when E is a class member access

Open
#5,342 4 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

[dcl.type.decltype] p1.3 states:

For an expression E, the type denoted by decltype(E) is defined as follows:

  • [...]
  • otherwise, if E is an unparenthesized id-expression or an unparenthesized class member access ([expr.ref]), decltype(E) is the type of the entity named by E. If there is no such entity, the program is ill-formed;

This sentence is obscure and subtle when E is a class member access. Consider this example:

struct C{
  int v;
};
C const obj{};  
decltype(obj.v) i;  // the type of i is `int` rather than `const int`. 
i = 0; // ok

We seem to never clearly specify what the entity named by a class member access is. [basic.pre] p3 just states that:

An entity is a value, object, reference, structured binding, function, enumerator, type, class member, bit-field, template, template specialization, namespace, or pack.

In this case, we can say the class member access E names the subobject associated with C::v or just names the class member C::v, they all be called entity. They have a huge different type due to the type of object expression(int vs. int const). It is not clear which is the correct interpretation, at least we never explicitly specify them in [expr.ref].

[expr.ref] p6 just specifies that

If E2 is a non-static data member..., the expression designates the corresponding member subobject of the object designated by the first expression.

Since [dcl.type.decltype] p1.3 references [expr.ref], we should clearly specify what the entity named by E1.E2 is, in [expr.ref].

Moreover, denote/named/designate should be explicitly defined if using them with the concrete component would have a different meaning.

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 [dcl.type.decltype] p1.3, [expr.ref] p6, and [basic.pre] p3, then work through the provided C++ example involving C::v and obj.v. Determine how the entity named by a class member access should be specified and whether denote, named, and designate need explicit definitions. Done means the relevant standard wording removes the ambiguity without changing the intended decltype behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.