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

[temp.param] p8 The value category of the non-type non-class non-reference parameter #4921

Open
xmh0511 opened this issue Sep 20, 2021 · 7 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Sep 20, 2021

The note that follows [temp.param] p8 says the category of such parameter is prvalue, however it is not a normative rule, and the note indicates that [expr.prim.id.unqual] has a concret interpretation. [expr.prim.id.unqual] says a variable is a lvalue. Since the grammar of a non-type template-parameter is parameter-declaration, which is the same with a function's parameter(a function's parameters are variables), hence the value category of such a template-parameter is a lvalue?

@jensmaurer
Copy link
Member

[expr.prim.id.unqual] says

The expression is an lvalue if the entity is a function, variable, structured binding (9.6), data member, or
template parameter object and a prvalue otherwise (7.2.1)

So, is it a variable? [basic.pre] p6 says a "variable is introduced by the declaration of [...] an object."

I think a scalar template parameter should not be an object (it does not occupy storage, has no storage duration, and doesn't really have lifetime), and I agree we could be clearer in [intro.object], with particular attention to "template parameter object" (which is, in fact, an object).

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 20, 2021

The definition for declaration of an object is never clear in the current draft, that is, the concept of a variable that has a dependency on that definition is not clear here. My argument is, the grammars of a non-type template parameter and of function's parameter are both parameter-declaration, however, the latter does introduce the variables. How do we interpret that difference? Moreover, for "does not occupy storage, has no storage duration, and doesn't really have lifetime" these concepts are not clear for non-type template parameters since these concepts are cross-referenced with each other.

For template parameter object, [expr.prim.id.unqual] has explicitly says it is an lvalue.

@jensmaurer
Copy link
Member

As long as we never ask about lifetime and storage duration for a scalar template parameter, we don't have to say anything about it. (There is a lingering issue with the relationship of variable and object in general: a local variable has several objects attached to it when the function is called recursively.)

I don't think it's the grammar that needs to make the difference here; it's enough to say that a scalar template parameter is not an object. The it can't be a variable and thus cannot be an lvalue, which is what we want.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 20, 2021

a scalar template parameter is not an object.

Right, that would be sufficient to fix this issue.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 24, 2021

Proposal:

[basic.pre] p6

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

@jensmaurer
Copy link
Member

That would imply that a non-type scalar template parameter declares an object. In my view, it doesn't.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 24, 2021

Ah, correct. The proposal is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants