Skip to content

[temp.param] Is a non-type template parameter that declares a reference a variable? #148

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

Open
xmh0511 opened this issue Oct 10, 2022 · 4 comments

Comments

@xmh0511
Copy link

xmh0511 commented Oct 10, 2022

Full name of submitter (unless configured in github; will be published with the issue): Jim X

A parameter-declaration that appears in a function declaration declares a variable. How about it appears as a template parameter? The issue arises from https://stackoverflow.com/questions/62567395/is-it-a-defect-about-a-non-type-template-parameter-of-a-reference-type-that-ther?noredirect=1#comment130536482_62567395.

The opinion in the comment on the question is that: Since a template parameter does not have storage and lifetime, it cannot be considered a variable. However, this point is not clear in the current standard.

@frederick-vs-ja
Copy link

A template parameter object does have storage and lifetime, but it is seemly not considered as a variable. Template parameter objects and constexpr variables of object types have some common properties: both of them are usable in constant expressions, and shall have constant destruction. Currently these properties are repeatedly specified.

I guess we should say that all NTTPs are not variables, or more precisely, declaration of a non-type template-parameter does not introduce an object or a reference (related to #82). And then we may specify that they (as _id-expression_s) are prvalues with some values or lvalues denoting some objects or functions (for scalar or non-scalar NTTPs respectively).

(So that the original problem might be resolved in the way that a NTTP of a reference type is not itself a reference, it's just a glvalue constant expression denoting an object or a function.)

@xmh0511
Copy link
Author

xmh0511 commented Oct 11, 2022

From a more general way, I think most issues I recently submit here regarding the parameter-declarations that appear as template parameters are actually the core issue: which declaration declares variable.

I agree with the opinion that all NTTP should not be a variable.


A template parameter object does have storage and lifetime, but it is seemly not considered as a variable.

This is a bit contradictory to the definition of the variable. [basic.pre] p6 says

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.

[temp.param] p8 says

An id-expression naming a non-type template-parameter of class type T denotes a static storage duration object of type const T, known as a template parameter object

we say the template parameter object denotes an object with static storage duration, and we say the id-expression(its name) denotes that object, which is exactly what the definition of variable tries to say.

@xmh0511
Copy link
Author

xmh0511 commented Oct 11, 2022

Another thing that should be noticed is, the parameter-declaration that appears in template-parameter is still a declaration. [basic.def] p1 says

A declaration may (re)introduce one or more names and/or entities into a translation unit.

Either the declaration only introduces a name(like a typedef declaration) or it introduces a name and entity. What does a parameter-declaration as a template parameter do? Does it introduce the name and entity? In the current, we say

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

If the parameter-declaration(as a template parameter) declares an entity, which one does it declare if we admit that the parameter-declaration is not a variable? This should be clarified.

@frederick-vs-ja
Copy link

CWG2983

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