C++ Logo

std-discussion

Advanced search

Potential defect in the standard when disambiguating function templates when one of them contains a pack

From: Anoop Rana <ranaanoop986_at_[hidden]>
Date: Sun, 19 Jun 2022 15:35:32 +0530
I was working with parameter packs when I noticed that one such case(given
below) doesn't compile in msvc but compiles fine in gcc and clang. Here is
the link for the verification of the same: link to demo
<https://godbolt.org/z/6hf7Ys1Tz>

The code is as follows:

template<typename T> struct C{};
template<typename T> void f(C<T>){
}template<typename... T> void f(C<T...>){
}int main(){
    f(C<int>{}); //Should this call succeed? }

I want to know if the above example is well-formed according to the
standard. I mean should the call *f(C<int>{}); *succeed by choosing the
first overload version `*void f(C<T>)*` over the second version.

For possible explanation i looked at examples given in: temp.deduct.type#9.2
<https://timsong-cpp.github.io/cppwp/n4861/temp.deduct.type#9.2>:
[Example

template<class T1, class... Z> class S;
 // #1template<class T1, class... Z> class S<T1, const Z&...> { };
       // #2template<class T1, class T2> class S<T1, const T2&> { };
             // #3
S<int, const int&> s; // both #2 and #3 match; #3 is more specialized

End Example]

My current understanding/intuition is that the example that I gave
here <https://godbolt.org/z/6hf7Ys1Tz> should be valid as well and the
first overload should be chosen over the second.

*If so*, should this or a similar example be added in temp.deduct.type
to make this more clear?
Basically I want to know if the intention for the same(i.e., for
allowing the example that i gave) was always there but was not clearly
conveyed. If not, then is there a clause that clear disallows

the example that i gave which i missed to notice/understand.

Received on 2022-06-19 10:05:45