显式专门化会导致实例化? [英] Explicit specialization incurs instantiation?
问题描述
回答此问题,我从GCC和Clang得到了一个惊人的错误:
Answering this question, I got a surprising error from GCC and Clang:
template< typename = void >
struct Outer_temp
{
struct Inner;
Inner myinner;
};
template<>
struct Outer_temp<void>::Inner // Error: specialization of Outer_temp
{ // with member myinner of incomplete type.
};
为什么声明显式特化需要隐式实例化?这是否与范围解析操作符的所有使用都属于同一类别?
Why does declaring an explicit specialization require implicit instantiation? Does this fall into the same category as all uses of the scope resolution operator?
实例化模板以查找成员对象的声明我会理解,但在这种情况下的成员类,可以检查该成员是否存在,并且是一个没有实例化任何东西的类。 (你确实需要部分专业化解析。)
Instantiating the template to find the declaration of a member object I would understand, but in the case of a member class, you can check that the member exists and is a class without instantiating anything. (You do need partial specialization resolution though.)
推荐答案
反思,这是语言设计固有的缺陷,的显式专业化。没有办法将显式专用化声明与成员声明进行匹配,无需实例化类模板及其所有成员声明。
On reflection, this is a flaw inherent to the language design and a quirk of explicit specialization. There is no way to match the explicit specialization declaration to the member declaration without instantiating the class template, and all its member declarations.
我不会提交缺陷报告,因为用例太小不用担心,它不会咬人有人不知道,因为当前的实现诊断条件。
I will not submit a defect report because the use case is too minor to worry about, and it won't bite someone unaware because current implementations diagnose the condition.
这篇关于显式专门化会导致实例化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!