With the following code gcc fails:
template <typename X = int, typename T, typename InIt, typename ...R>
inline void func(const T& t, InIt b, InIt e, R... p) {}
template <typename X = int, typename T, typename Iterable, typename ...R>
inline void func(const T& t, const Iterable& i, R... p) {}
template <typename T>
struct S {};
template <typename X = int, typename T, typename InIt, typename ...R>
inline void func(const S<T>& t, InIt b, InIt e, R... p) {}
template <typename X = int, typename T, typename Iterable, typename ...R>
inline void func(const S<T>& t, const Iterable& i, R... p) {}
int main() {
func(42, "");
func(S<int>(), "");
func(S<int>(), "", 1); // error
}
with:
<source>: In function 'int main()':
<source>:16:25: error: call of overloaded 'func(S<int>, const char [1], int)' is ambiguous
func(S<int>(), "", 1);
^
<source>:16:25: note: candidates are:
<source>:4:17: note: void func(const T&, const Iterable&, R ...) [with X = int; T = S<int>; Iterable = char [1]; R = {int}]
inline void func(const T& t, const Iterable& i, R... p) {}
^
<source>:11:17: note: void func(const S<T>&, const Iterable&, R ...) [with X = int; T = int; Iterable = char [1]; R = {int}]
inline void func(const S<T>& t, const Iterable& i, R... p) {}
Tested with gcc v4.8.1 and v9.1. Compiles with clang (v3 and v8), icc (v13 and v19), msvc (v19.14 and v19.20).
Is the code valid or is this a bug in gcc?
Aucun commentaire:
Enregistrer un commentaire