Topic: Class definition isn't complete


Author: Gianni Luciani <gianni.luciani@tiscalinet.it>
Date: 2000/12/04
Raw View
Hallo,

can anybody turn on light over the following problem ?

Given the following definitions:

template<int dim> class TheDim { // uses dim
};

class ProvaStaticDef { // other stuff
    static TheDim<sizeof(ProvaStaticDef)> m_provaDim;
};

// In file provastaticdef.cpp
TheDim<sizeof(ProvaStaticDef)> ProvaStaticDef::m_provaDim;

A Borland compiler flags the above code with the following error
(i.e. it issues a diagnostic) :
[C++ Error] ProvaStaticDef.h(67): E2450 Undefined structure 'ProvaStaticDef'
[C++ Error] ProvaStaticDef.h(67): E2109 Not an allowed type

A Microsoft compiler flags the code with an error, too (just another diagnostic) :
provastaticdef.h(61) : error C2027: use of undefined type 'ProvaStaticDef'

Ok, the above code is ill-formed, but precisely why (i.e. which Standard clause
did it hurt) ?
Well, I know that at the time of using ProvaStaticDef it isn't still defined,
but static data members doesn't contribute to the layout of a class (i.e. they
shouldn't influence class dimension, if I remember well), so there is no
reason/need to start static data member declaration/definition before the
class is fully defined;
it can be done after that (even without a 2nd pass over code but just
'remembering' it).

What are true reasons for the above behaviour, i.e. which wrong assumptions
am I relying on ?

Gianni Luciani

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: Andrei Iltchenko <Andrei.Iltchenko@openmarket.com>
Date: 2000/12/05
Raw View
Gianni Luciani wrote:

> Hallo,
>
> can anybody turn on light over the following problem ?
>
> Given the following definitions:
>
> template<int dim> class TheDim { // uses dim
> };
>
> class ProvaStaticDef { // other stuff
>     static TheDim<sizeof(ProvaStaticDef)> m_provaDim;
> };
>
> // In file provastaticdef.cpp
> TheDim<sizeof(ProvaStaticDef)> ProvaStaticDef::m_provaDim;
>
> A Borland compiler flags the above code with the following error
> (i.e. it issues a diagnostic) :
> [C++ Error] ProvaStaticDef.h(67): E2450 Undefined structure 'ProvaStaticDef'
> [C++ Error] ProvaStaticDef.h(67): E2109 Not an allowed type
>
> A Microsoft compiler flags the code with an error, too (just another diagnostic) :
> provastaticdef.h(61) : error C2027: use of undefined type 'ProvaStaticDef'
>
> Ok, the above code is ill-formed, but precisely why (i.e. which Standard clause
> did it hurt) ?
> Well, I know that at the time of using ProvaStaticDef it isn't still defined,
> but static data members doesn't contribute to the layout of a class (i.e. they
> shouldn't influence class dimension, if I remember well), so there is no
> reason/need to start static data member declaration/definition before the
> class is fully defined;
> it can be done after that (even without a 2nd pass over code but just
> 'remembering' it).
>
> What are true reasons for the above behaviour, i.e. which wrong assumptions
> am I relying on ?
>
> Gianni Luciani
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
> [ Note that the FAQ URL has changed!  Please update your bookmarks.     ]

Gianni,

> template<int dim> class TheDim { // uses dim
> };
>
> class ProvaStaticDef { // other stuff
>     static TheDim<sizeof(ProvaStaticDef)> m_provaDim;
> };
>
> // In file provastaticdef.cpp
> TheDim<sizeof(ProvaStaticDef)> ProvaStaticDef::m_provaDim;

The code above is illegal because of the following:

Section 5.3.3 paragraph 1 states that an operand of the sizeof
operator shall not have an incomplete type.

Section 9.2 paragraph 2 of the standard says that a class is
considered complitely-defined at the closing } of the
class-specifier.

Regards,
Andrei.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: "Gene Bushuyev" <gbush@deja.com>
Date: 2000/12/05
Raw View
"Gianni Luciani" <gianni.luciani@tiscalinet.it> wrote in message
news:Pine.LNX.4.21.0012040047550.831-100000@deimos.solarsystem.gnu...
> Hallo,
>
> can anybody turn on light over the following problem ?
>
> Given the following definitions:
>
> template<int dim> class TheDim { // uses dim
> };
>
> class ProvaStaticDef { // other stuff
>     static TheDim<sizeof(ProvaStaticDef)> m_provaDim;
> };
[snip]

The sizeof operator shall not be applied to an expression that has function
or incomplete type ... 5.3.3/1
--
-------------------------
Gene Bushuyev
"A free people ought to be armed." - George Washington


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]