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

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

概述概要 我正在努力使C11代码Clang兼容,并且遇到GCC> = 4.6接受代码并且Clang> = 3.1的情况. Clang认为候选建设者不可行. 细节 这是一个修剪下来的例子来说明这个问题: #include <utility>template <typename...>struct T;template<>struct T<>{ typedef T super; 概要

我正在努力使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. 总结

以上是内存溢出为你收集整理的c – Clang问题:在施工时的隐式类型转换全部内容,希望文章能够帮你解决c – Clang问题:在施工时的隐式类型转换所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1243694.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存