cplusplus / cplusplus/draft

Inconsistencies with "object declarations", "declarations that declare objects" and "class members of object type"

Open
#1,280 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

Richard asked me to add the following std-discussion content as an issue (the original question was about "A variable is introduced by the declaration of a reference other than a non-static data member or of an object.").

I still don't understand. I can see why a non-static data member is
not the declaration of an object.. because the (sub-) object is only
there once we create an object of the membering class. But how do
references differ in that regard? They too are not "there
immediately", but require an object of the membering class to
necessiate the beginning of the lifetime of a reference for each such
object.

I suppose the problem is in the ambiguity of what a "declaration of a
reference" is. I believe the intent here is that a "declaration of a
reference" is a declaration that declares a particular name to be of
reference type (which a non-static data member declaration of reference type
does), not necessarily a declaration that causes the lifetime of a
particular reference to begin. Conversely, a "declaration of an object" is
intended to be interpreted as a declaration that declares a particular name
to name a specific object (which a non-static data member declaration does
not).

That is:

struct A {
  int &a;
  int b;
};

'a' is a declaration of a reference, and so we need another condition to
restrict it from being a variable. 'b' is /not/ a declaration of an object,
so we don't need to say anything further.

Suggestions on how to reword this to make it clearer would be welcome :)

OK, thanks I see. But, is this intent worded somewhere in the spec
aswell? As far as declarations that contain decl-specifier-seq are
concerned we have at 7p10 that says

"If the decl-specifier-seq contains no typedef specifier, the declaration is called a function declaration if the type associated with the name is a function type ([dcl.fct]) and an object declaration otherwise.".

Am am not totally sure whether this only applies to
simple-declarations (because of the location of that paragraph), or
whether it applies to all declarations that contain
decl-specifier-seqs. Another thing is, because it indicate that an
"object declaration" is not quite the same as a "declaration of an
object", it becomes very involved. Are the following summaries correct
based on your answers and the spec?

struct A  {
   int &b; // Not the declaration of an object. But an object declaration. And the declaration of a reference
   int c; // Not the declaration of an object. But an object declaration
};

extern int &d; // Not the declaration of an object. But an object declaration. And the declaration of a reference
int e; // The declaration of an object. And an object declaration. But not the declaration of a reference

Are they correct concerning the intent? Would it not make sense to
distinguish between object declarations and reference declarations?
Other places in the spec seem to use "object declaration" as implying
that they declare objects, like 7.1.5p9:

"A constexpr specifier used in an object declaration declares the object as const."

On the other hand, there's evidence that other places use "object
declaration" to mean "declaration that gives names an object or
reference type", such as 8.2p1:

"In that context, the choice is between a function declaration with a redundant set of parentheses around a parameter name and an object declaration with a function-style cast as the initializer."

This indicates that this term "object declaration" was not updated
properly when references were added to the language?

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 comparing the terminology in the cited clauses 7p10, 7.1.5p9, and 8.2p1 with the examples in the issue. Determine whether the terms are intended to distinguish object, reference, and object declarations, then document a consistent resolution and identify the affected standard wording.

Written by the indexing model from the issue text.

Assessment

Tech stack
tex
Domain
documentation
Issue type
Documentation
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.