c++ - g++ Bug with Partial Template Specialization -
i writing tmp-heavy code g++ (version 4.8.1_1, macports) , clang++ (version 3.3, macports). while g++ rejects following code listing unbridled fury, clang++ compiles grace , splendor.
- which complier in right? (i suspect it's g++, want reassurance others before submitting bug report.)
- do have easy or elegant workarounds suggest? (i need use template aliases, switching on structs, causes g++ accept code, not option.)
here code listing, made just you.
template <class... ts> struct sequence; template <int t> struct integer; // definition of `extents` causes g++ issue compile-time error. template <int... ts> using extents = sequence<integer<ts>...>; // however, definition works without problems. // template <int... ts> // struct extents; template <int a, int b, class current> struct foo; template <int a, int b, int... ts> struct foo<a, b, extents<ts...>> { using type = int; }; template <int b, int... ts> struct foo<b, b, extents<ts...>> { using type = int; }; int main() { using t = foo<1, 1, extents<>>::type; return 0; }
here g++'s output:
er.cpp: in function 'int main()': er.cpp:39:41: error: ambiguous class template instantiation 'struct foo<1, 1, sequence<> >' using t = typename foo<1, 1, extents<>>::type; ^ er.cpp:26:8: error: candidates are: struct foo<a, b, sequence<integer<ts>...> > struct foo<a, b, extents<ts...>> ^ er.cpp:32:8: error: struct foo<b, b, sequence<integer<ts>...> > struct foo<b, b, extents<ts...>> ^ er.cpp:39:43: error: 'type' in 'struct foo<1, 1, sequence<> >' not name type using t = typename foo<1, 1, extents<>>::type; ^
here clang++'s output:
thanks help!
this seems g++ bug because foo<b, b, extents>
more specialized foo<a, b, extents>
(te latter can match former matches, not vice versa), compiler should choose specialization.
as noted yourself, changing extents
template alias class template, solves problem.
Comments
Post a Comment