This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/58354] New: variadic template ambigous
- From: "1zeeky at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 07 Sep 2013 12:23:36 +0000
- Subject: [Bug c++/58354] New: variadic template ambigous
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58354
Bug ID: 58354
Summary: variadic template ambigous
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: 1zeeky at gmail dot com
Created attachment 30761
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30761&action=edit
testcase
I have a templated function, which recursively calls itself.
The stopping criterion is provided via a std::integral_constant<std::size_t>
that gets incremented each iteration and upon a certain value should call an
overload that does not recurse.
There are two requirements to get g++ to claim that the call is ambiguous:
There must be an extra template-parameter that is explicitly specified when
recursing (typename T in the testcase) and variadic templates must be used.
If either is not present, it compiles fine.
If variadic templates are present, but no additional arguments are passed (like
the second parameter for foo (0) in the testcase), it compiles fine.
clang 3.3 compiles this code fine, and given that the mentioned extra
requirements must be met to make the call ambiguous I'm somewhat confident that
it is valid C++.
This is the specific output the attached testcase generates for g++ 4.8.1:
test.cpp: In instantiation of âvoid foo(IndexType<index>, Arguments ...) [with
T = int; long unsigned int index = 0ul; Arguments = {}; IndexType<index> =
std::integral_constant<long unsigned int, 0ul>]â:
test.cpp:15:25: required from here
test.cpp:11:76: error: call of overloaded âfoo(IndexType<1ul>, int)â is
ambiguous
void foo(IndexType<index>, Arguments...) { foo<T>(IndexType<index + 1>(), 0);
}
^
test.cpp:11:76: note: candidates are:
test.cpp:8:6: note: void foo(IndexType<1ul>, Arguments ...) [with T = int;
Arguments = {int}; IndexType<1ul> = std::integral_constant<long unsigned int,
1ul>]
void foo(IndexType<1>, Arguments...) { }
^
test.cpp:11:6: note: void foo(IndexType<index>, Arguments ...) [with T = int;
long unsigned int index = 1ul; Arguments = {int}; IndexType<index> =
std::integral_constant<long unsigned int, 1ul>]
void foo(IndexType<index>, Arguments...) { foo<T>(IndexType<index + 1>(), 0);
}
^