This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Compiler bug?
This mail doesn't use the standard, but is an analysis of the
problem by me. Imho, it shows that this *should* be a bug.
If one adds an instantiation just before
the definition of s, the compiler error goes away:
template<typename T>
struct Outer
{
struct Inner
{
int c;
static int s[];
};
};
extern template class Outer<char>; // Added
template<typename T>
int Outer<T>::Inner::s[sizeof(Inner)];
extern template class Outer<char>;
That is rather inconsistant.
The incomplete type probably comes from the fact that the size
of 's' is not known at that point. So, the question is, should
it complain because of that?
Because
// Not a template anymore
struct Outer
{
struct Inner
{
int c;
static int s[];
};
};
int Outer::Inner::s[sizeof(Inner)];
Outer instance; // Instantiation
compiles fine it probably shouldn't complain in the first
case either. However - it isn't logical to use the first
in a real life program unless 'Inner' uses/contains the
type T - so a relevant question is: is sizeof(T) known at
that point (which would be needed to calculate sizeof(Inner)
in practical cases)? When it is not then this might not
be a bug.
However,
template<typename T>
struct Outer
{
struct Inner
{
int c;
static int s[];
};
};
template<typename T>
int Outer<T>::Inner::s[sizeof(T)];
extern template class Outer<char>;
compiles fine - and therefore your case is either a bug, or
there is an inconsistancy in the standard, imho.
--
Carlo Wood <carlo at alinoe dot com>