【发布时间】:2017-04-15 20:24:25
【问题描述】:
考虑以下class 定义和deduction guide:
template <typename... Ts>
struct foo : Ts...
{
template <typename... Us>
foo(Us&&... us) : Ts{us}... { }
};
template <typename... Us>
foo(Us&&... us) -> foo<Us...>;
如果我尝试使用显式模板参数来实例化foo,代码编译正确:
foo<bar> a{bar{}}; // ok
如果我尝试通过演绎指南实例化foo...
foo b{bar{}};
-
g++7 产生编译器错误:
prog.cc: In instantiation of 'foo<Ts>::foo(Us ...) [with Us = {bar}; Ts = {}]': prog.cc:15:16: required from here prog.cc:5:27: error: mismatched argument pack lengths while expanding 'Ts' foo(Us... us) : Ts{us}... { } ^~~ -
clang++5 爆炸:
#0 0x0000000001944af4 PrintStackTraceSignalHandler(void*) (/opt/wandbox/clang-head/bin/clang-5.0+0x1944af4) #1 0x0000000001944dc6 SignalHandler(int) (/opt/wandbox/clang-head/bin/clang-5.0+0x1944dc6) #2 0x00007fafb639a390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390) #3 0x0000000003015b30 clang::Decl::setDeclContext(clang::DeclContext*) (/opt/wandbox/clang-head/bin/clang-5.0+0x3015b30) ... clang-5.0: error: unable to execute command: Segmentation fault
虽然 clang++ 确实存在问题 (报告为问题 #32673),但 g++ 拒绝我的代码是否正确? 我的代码格式不正确吗?
【问题讨论】:
-
具体问题好像是
Ts是not correctly deduced
标签: c++ c++17 template-argument-deduction