in order practice c++11, i'm playing variadic templates.
in particular, i'm playing sort of recursive variadic container class (onion
) , function returns number of template types (func()
).
i came across case clang++ (3.5.0) can't compile while g++ (4.9.2) compiles , runs no problems.
i have simplified follows
#include <iostream> template <typename f, typename ... o> struct onion; template <typename f, typename s, typename ... o> struct onion<f, s, o...> { f first; onion<s, o...> others; }; template <typename l> struct onion<l> { l last; }; template <typename ... args> std::size_t func (onion<args...> const &) { return sizeof...(args); } int main() { auto o = onion<int, char const *, float> { 23, { "abcd", {34.0f}} }; std::cout << func(o) << '\n'; return 0; }
clang++ (3.5.0) gives me following compiler error
test.cpp:28:17: error: no matching function call 'func' std::cout << func(o) << '\n'; ^~~~ test.cpp:20:13: note: candidate template ignored: substitution failure [with args = <>]: few template arguments class template 'onion' std::size_t func (onion<args...> const &) ^ ~~~~~ 1 error generated.
g++ (4.9.2) compiles without problem and, running, output 3
.
my question is: who's right?
clang++, giving error, or g++, compiling?
i add if rewrite func()
in way
template <typename x, typename ... args> std::size_t func (onion<x, args...> const &) { return 1u + sizeof...(args); }
or if redefine onion
in way
template <typename ... o> struct onion;
both clang++ , g++ compile without errors.
this looks compiler bug in clang 3.5. if run code trunk version compiles nicely.
Comments
Post a Comment