cplusplus / cplusplus/draft

The unclear definition for "variable"

Open
#4,749 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

As @opensdh answered in this https://stackoverflow.com/questions/65319283/how-to-understand-the-concept-of-variable issue, the definition of the variable is unclear and generally confused by the standard. Also, @languagelawyer did some efforts on clarifying it.

A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable's name, if any, denotes the reference or object.

I think the essence of this issue is that we use the declaration with a general meaning. In other words, the declaration may refer to declaration defined in [dcl.dcl] or member-declaration in [class.mem], or parameter-declaration in [dcl.fct], or so on, as long as it is a declaration with the meaning in English.

Why don't we use the defined grammar to eliminate these ambiguous things? Although, use the wording "declaration" is a convenient way to define some rules, sometimes it could result in some ambiguities as the question discussed in the above issue. Maybe, the definition for variable could be that

A variable is first introduced by the declaration, parameter-declaration, exception-declaration, member-declaration that declares static data member, ...(some other declarations if I omitted) of a reference or of an object. The variable's name, if any, denotes the reference or object.

These italic wordings all refer to the corresponding grammar. It would be a clear(strict) definition.

Or, if the first approach looks too long, we may define what is a declaration of an object. More precisely, which declarations create objects?

@jensmaurer @opensdh @languagelawyer @jwakely

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 definition quoted in the issue and read the referenced grammar clauses [dcl.dcl], [class.mem], and [dcl.fct]. Compare the existing use of “declaration” with the proposed grammar-specific wording, then confirm that the chosen definition removes the reported ambiguity without omitting relevant declaration forms.

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
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.