clang: candidate template ignored: substitution failure: typedef 'type' cannot be referenced with a class specifier

Viewed 1059

In contrast to GCC 5, Clang 6 complains about the following error:

candidate template ignored: substitution failure [with U = char, Us = ]: typedef 'type' cannot be referenced with a class specifier Tuple(U&& u, Us&&... rest) : m_element(::std::forward(u)), m_rest(::std::forward(rest...)...)

I use my own Tuple implementation with

//! Declaration of tuple typename with multiple elements
template<typename T, typename... Ts>
class Tuple<T, Ts...>
{
public:
    T m_element;
    Tuple<Ts...> m_rest;

    template<typename U,
             typename... Us,
             typename = class ::std::enable_if<!::std::is_base_of<Tuple,typename ::std::decay<U>::type>::value>::type>
    Tuple(U&& u, Us&&... rest) : m_element(::std::forward<U>(u)), m_rest(::std::forward<Us>(rest)...)
    {
    }
};

template<typename... Ts>
Tuple<typename ::std::decay<Ts>::type...> make_tuple(Ts&&... elements)
{
    return Tuple<typename ::std::decay<Ts>::type...>(::std::forward<Ts>(elements)...);
}

What is clang doing differently than GCC? And how can I fix this?

Thanks!

1 Answers

What is clang doing differently than GCC? And how can I fix this?

Non sure who's right and not sure this solve your problem (without a minimal but complete example of your problem I can't check it) but I have an error (clang++ only) that disappear when I change a class with a typename

So I suggest

template<typename U,
         typename... Us,
         // ........VVVVVVVV  <--- "typename" here, not "class"
         typename = typename ::std::enable_if<!::std::is_base_of<Tuple,typename ::std::decay<U>::type>::value>::type>
Tuple(U&& u, Us&&... rest) : m_element(::std::forward<U>(u)), 
                             m_rest(::std::forward<Us>(rest)...)
 { }
Related