This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Vararg templates. GCC vs Clang
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Victor <d dot v dot a at ngs dot ru>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Sat, 7 Feb 2015 00:05:29 +0000
- Subject: Re: Vararg templates. GCC vs Clang
- Authentication-results: sourceware.org; auth=none
- References: <web-4861695 at mx53 dot intranet dot ru>
On 6 February 2015 at 12:12, Victor <d.v.a@ngs.ru> wrote:
>
>
>
> --- the forwarded message follows ---
>
>
> ---------- Forwarded message ----------
> From: Victor <d.v.a@ngs.ru>
> To: gcc-help@gcc.gnu.org
> Cc:
> Date: Wed, 04 Feb 2015 15:41:56 +0600
> Subject: Vararg templates. GCC vs Clang
> Code:
>
> #include<tuple>
> #include<iostream>
>
> template<class Head, class... Tail>
> void f(std::tuple<Head, Tail...> )
> {
> std::cout << "std::tuple<Head, Tail...>\n";
> }
>
> template<class Head>
> void f(std::tuple<Head> )
> {
> std::cout << "std::tuple<Head>\n";
> }
>
> int main()
> {
> f(std::tuple<int>{});
> }
>
> GCC accepts this code silently. But Clang generates error:
>
> test.cpp:18:5: error: call to 'f' is ambiguous
> f(std::tuple<int>{});
> ^
> test.cpp:5:6: note: candidate function [with Head = int, Tail = <>]
> void f(std::tuple<Head, Tail...> )
> ^
> test.cpp:11:6: note: candidate function [with Head = int]
> void f(std::tuple<Head> )
> ^
>
> Which compiler is right? Isn't it abiguity in fact?
This question would have been more appropriate on the gcc-help mailing list.
Technically the standard says it's ambiguous, but the C++ committee
believes that to be a defect and plan to fix it, see
http://open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1395