C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Potential defect in the standard when disambiguating function templates when one of them contains a pack

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Sat, 18 Jun 2022 18:40:45 +0200
On 18/06/2022 14.26, Anoop Rana via Std-Proposals wrote:
> 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; // #1
> template<class T1, class... Z> class S<T1, const Z&...> { }; // #2
> template<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]

Could you make C take a pack of T? Does the issue reproduce?

> 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?

Did you post a bug report to the vendor? What was their response?

Jens

Received on 2022-06-18 16:40:48