Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The unclear definition for "variable" #4749

Open
xmh0511 opened this issue Jul 14, 2021 · 2 comments
Open

The unclear definition for "variable" #4749

xmh0511 opened this issue Jul 14, 2021 · 2 comments
Labels
cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Jul 14, 2021

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

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 30, 2021

Regardless of [expr.prim.id.unqual] or [expr.prim.id.qual], they all admit the non-static data member they denotes is an lvalue. An lvalue denotes an object, as per [basic.lval#1.1]. So, when we mention a variable or variable's definition, should we consider the non-static data member of object type? @languagelawyer

@jensmaurer
Copy link
Member

Instead of trying to mess with the definition of "variable" editorially, we should really address this in a paper, which also clarifies the relationship between variable and object.

@jensmaurer jensmaurer added cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking. labels Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.
Projects
None yet
Development

No branches or pull requests

2 participants