From: Johannes Schaub (litb) on
Randy wrote:

> On Mar 9, 8:19 am, Kris Prad <krisp...(a)yahoo.co.uk> wrote:
>
> [snip]
>
>> Comeau accepts even this:
>>
>> #include <vector>
>>
>> struct A
>> {
>> std::vector<A> vec_;
>> A(): vec_(10) {} // <----- with size
>>
>> };
>>
>> BUT NOT THIS:
>>
>> struct B;
>> std::vector<B> vec2_; // incomplete type error
>>
>> Kris
>>
>
> Actually this example appears, IMHO, to be correct based on my reading
> of the Standard, 9.2, Class Members, paragraph 2, which states that a
> class is considered as a complete type at several points in the class
> member specification, explicitly including in ctor initializer lists,
> as shown above.
>

If the semantics require the class type "vector<A>" to be complete, it's
instantiated. A non-static data member definition is such a point: It
requires its type to be complete.

Thus, at "std::vector<A> vec_" an implicit instantiation of the vector type
occurs. The point of instantiation will be prior to "A", so class type "A"
is incomplete within std::vector and thus behavior is undefined.

However, the consideration about what consequences the POI has with regard
to completeness and visibility of subsequent declarations is quite
convoluted - see http://www.open-
std.org/jtc1/sc22/wg21/docs/cwg_active.html#287 ).

In the case of a specialization reference from within a member function body
defined in-class or a ctor-initializer in-class and the other cases where a
class is regarded complete, it seems to me that the current rules do not
clearly state what happens. In other words, currently the following is not
guaranteed to work because the completeness in the context of the ctor-
initializer does not seem to carry over into the instantiated
specialization:

template<typename T> struct B { static int const value = sizeof(T); };

// # POI is here, prior to A.
struct A {
int m;
A():m(B<A>::value) { }
};

The there mentioned rules to add after paragraph 3 seem to be important to
guarantee that this indeed works. In any case, GCC and comeau already accept
this code.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]