【发布时间】:2018-11-01 19:14:00
【问题描述】:
假设我有这个示例类型:
template < class T = void > struct Test { };
template < > struct Test<void> { };
还有这个类型的扣分指南:
template<class T> Test() -> Test<T>;
下面的编译就好了:
Test f;
在 GCC 上。
但是,在 Clang 上。扣分指南需要:
template<class T = void> Test() -> Test<T>;
所以我的问题是:哪个是正确的?
默认模板类型应该同时出现在推导和基类型中,还是只出现在基类型中,并假设它会被编译器拾取。
GCC 和 Clang 的主干版本都在 godbolt.org 上使用-O3 -std=c++17进行了测试
【问题讨论】:
标签: c++ templates g++ c++17 clang++