Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top