Explicit specialization incurs instantiation?

守給你的承諾、 提交于 2019-12-23 02:48:07

问题


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.)


回答1:


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.



来源:https://stackoverflow.com/questions/20110225/explicit-specialization-incurs-instantiation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!