简体   繁体   English

clang: 候选模板被忽略: 替换失败: typedef 'type' 不能用类说明符引用

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

In contrast to GCC 5, Clang 6 complains about the following error:与 GCC 5 相比,Clang 6 抱怨以下错误:

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...)...)候选模板被忽略:替换失败 [with U = char, Us = ]: typedef 'type' 不能用类说明符引用 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?铿锵与 GCC 有何不同? And how can I fix this?我该如何解决这个问题?

Thanks!谢谢!

What is clang doing differently than GCC?铿锵与 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不知道谁是正确的,并不能肯定这解决您的问题(没有你的问题的一小部分,但完整的例子,我不能检查它),但我有一个错误(铛++只),其消失的时候我改变classtypename

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)...)
 { }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 候选模板被忽略:替换失败(clang但不是g ++错误) - candidate template ignored: substitution failure(error with clang but not g++) “忽略候选模板:替换失败:”编译器错误? - "candidate template ignored: substitution failure:" compiler error? 忽略Clang候选模板:替换失败(也无法使用gcc编译,VC工作正常) - Clang candidate template ignored: substitution failure (also fails to compile with gcc, VC works fine) “候选模板被忽略:替换失败”错误帮助,C ++,犰狳,rank(), - 'candidate template ignored: substitution failure' error help, C++, Armadillo, rank(), clang 3.3中的模板默认Arg替换失败 - Template Default Arg Substitution failure in clang 3.3 在函数模板签名中忽略了成员typedef的访问说明符 - Access specifier for member typedef ignored in function template signature SFINAE失败,类模板中的typedef引用了另一个类模板中的typedef - SFINAE failure with typedef in class template referring to typedef in another class template 用c ++ typedef /类型替换枚举类 - c++ typedef/type substitution for enumeration class 替换失败的模板特化 - Template specialisation on substitution failure 协变量返回类型取决于模板类typedef - covariant return type depending on a template class typedef
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM