以下C++ 11代码使用g ++ 4.7.4,g ++ 4.8.5,g ++ 4.9.3和g ++ 5.3.0编译,但不能与clang ++ 3.7.1或clang ++编译3.8.0(主干254750):使用非类型参数的奇怪模板实例化错误
template <typename F, F f> struct MetaValue {};
template <typename T> class IntSpec;
template <int V> class IntSpec<MetaValue<int, V> > {};
// note: template is declared here:
template <typename T> class PtrSpec;
template <void * V> class PtrSpec<MetaValue<void *, V> > {};
int main() {
IntSpec<MetaValue<int, 0> >();
// implicit instantiation of undefined template 'PtrSpec<MetaValue<void *, nullptr> >'
PtrSpec<MetaValue<void *, nullptr> >();
}
锵只IntSpec<>
上的PtrSpec<>
实例错误,但不是。这是一个编译器错误,标准中的含糊不清或者我在编写代码时总是需要考虑的东西?如有可能,请提供参考。
编辑:我进一步分析发现,两种编译了以下工作:
template <typename F, F f> struct MetaValue {};
// note: template is declared here:
template<typename T> class PtrSpec;
template <int * V> class PtrSpec<MetaValue<int *, V> > {};
extern int x;
int main() { PtrSpec<MetaValue<int *, &x> >(); }
,但如果我改变&x
到nullptr
我得到implicit instantiation of undefined template 'PtrSpec<MetaValue<int *, nullptr> >'
铿锵++。
文件铿锵的错误。他们会想要解决这个问题。 – Graznarak
@Graznarak Nah,没有足够的动机atm。 – jotik