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.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- MTD的坏块管理(一)-快速了解MTD的坏块管理
- oracle获取当前时间,精确到毫秒并指定精确位数的
- c# – 抛出System.ExecutionEngineException
- 将xml数据加载到hive表中:org.apache.hadoop.hi
- c# – Console.SetWindowPosition – >居中(每次
- cocos2d-x 3.2 之 三消类游戏——万圣大作战 (第
- visual-c – 我在哪里将字符串库包含在我的C头文
- OFBIZ分享:关于contronal.xml 文件中response的
- 深入解析NoSQL数据库的分布式算法
- React Native 和ionic2 你选择哪一个?
热点阅读