C++ Logo

std-discussion

Advanced search

The issue about reference collapsing for function parameter pack

From: jim x <xmh970252187_at_[hidden]>
Date: Wed, 2 Sep 2020 20:48:45 +0800
About the reference collapsing, its rule is defined as the following:

>If a *typedef-name* ([dcl.typedef], [temp.param]) or a *decltype-specifier*
denotes a type TR that is a reference to a type T, an attempt to create the
type “lvalue reference to cv TR” creates the type “lvalue reference to T”,
while an attempt to create the type “rvalue reference to cv TR” creates the
type TR.

However, consider such a case:
````
template<typename...T>
void func(T&&...args){
}
int main(){
   int a{};
   char b{};
   func(a,b);
}
````
we know the deduced template argument are `int&` and `char&`. That is, the
function type is void(int&,char&). we know the reference collapsing rules
is applying for this case. However, I have to say that the identifier `T`
is neither a typedef-name nor decltype-specifier, because of the following
rule:

*A type-parameter whose identifier does not follow an ellipsis defines its
identifier to be a typedef-name *(if declared without template) or
template-name (if declared with template) in the scope of the template
declaration.

So, these rules are contradicting with each others. How to interpret this?
Is it a defect in the standard?

Received on 2020-09-02 07:52:26