加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – Clang问题:在施工时的隐式类型转换

发布时间:2020-12-16 04:59:19 所属栏目:百科 来源:网络整理
导读:概要 我正在努力使C11代码Clang兼容,并且遇到GCC = 4.6接受代码并且Clang = 3.1的情况. Clang认为候选建设者不可行. 细节 这是一个修剪下来的例子来说明这个问题: #include utilitytemplate typename...struct T;templatestruct T{ typedef T super; conste
概要

我正在努力使C11代码Clang兼容,并且遇到GCC> = 4.6接受代码并且Clang> = 3.1的情况. Clang认为候选建设者不可行.

细节

这是一个修剪下来的例子来说明这个问题:

#include <utility>

template <typename...>
struct T;

template<>
struct T<>
{
    typedef T super;

    constexpr T() { }

    template <typename... Args>
    T(Args&&...) { }

};

template <typename Head,typename... Tail>
struct T<Head,Tail...> : T<Tail...>
{
    typedef T<Tail...> super;

    Head head;

    T(Head arg) : super(),head(std::move(arg)) { }
};


struct void_type
{
    constexpr void_type() { }
    constexpr void_type(const void_type&) { }
    void_type& operator=(const void_type&) = default;

    template <typename Arg0,typename... Args>
    void_type(Arg0&&,Args&&...) { }
};

struct atom { };

int main()
{
    atom a;
    T<void_type> t(a);

    return 0;
}

我得到的错误是:

ctor-init.cpp:44:18: error: no matching constructor for initialization of 'T<void_type>'
    T<void_type> t(a);
                 ^ ~
ctor-init.cpp:19:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'atom' to 'const T<void_type>' for 1st argument;
struct T<Head,Tail...> : T<Tail...>
       ^
ctor-init.cpp:25:5: note: candidate constructor not viable: no known conversion from 'atom' to 'void_type' for 1st argument;
    T(Head arg) : super(),head(std::move(arg)) { }
    ^
1 error generated.

我不明白为什么cl声抱怨缺少转换的可能性,因为我认为这个“全部”构造函数应该可以工作:

template <typename Arg0,typename... Args>
void_type(Arg0&&,Args&&...) { }

所以我很困惑的错误是:

ctor-init.cpp:25:5: note: candidate constructor not viable: no known conversion from 'atom' to 'void_type' for 1st argument;
    T(Head arg) : super(),head(std::move(arg)) { }
    ^

毕竟,GCC接受代码.这可能是一个ang虫吗? (我正在使用最新的Clang从LLVM git存储库.)

解决方法

的确,这是一个ang臭.原来,可变的构造函数被错误地标记为显式. Fixed in Clang r158040.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读