Topic: Defect Report: Restrictions on use of incomplete types not
Author: Michiel Salters<Michiel.Salters@cmg.nl>
Date: Wed, 19 Dec 2001 16:16:22 CST Raw View
In article <9vn11n$gr$1@bcarh8ab.ca.nortel.com>, Anthony Williams says...
>
>"Michiel Salters" <Michiel.Salters@cmg.nl> wrote in message
>news:1n4T7.747$XC5.27@www.newsranger.com...
>> In article <9v4iil$d4qvl$1@ID-49767.news.dfncis.de>, Anthony Williams
>says...
>> >
>> >"Michiel Salters" <Michiel.Salters@cmg.nl> wrote in message
>> >news:lN%Q7.55820$xS6.89347@www.newsranger.com...
>> >> Is it legal to use an incomplete type (3.9 [basic.types] /6 ) as a
>> >> class member, if no object of such class is ever created ?
>> >>
>> >> And as a class template member, even if the template is instantiated,
>> >> but no object of the instantiated class is created?
>> >>
>> >> The consensus seems to be NO, but no wording was found in the standard
>> >> which explicitly disallows it.
>> >>
>> >> The problem seems to be that most of the restrictions on incomplete
>types
>> >> are on their use in objects, but class members are not objects.
>> >
>> >Class members are objects. 1.8p2
>> 1.8 applies to members of objects, not members of classes.
>
>OK, agreed that 1.8 applies to objects, but 9.2p8 says:
>
>"Non-static (9.4) members that are class objects shall be objects of
>previously defined classes."
>
>This implies that class members are objects, as how else can they be class
>objects?
Some (most) class members are used to create objects, by creating an object
of the complete type. But the entire point was that we're not creating
objects of the cmplete type.
[SNIP]
>The other incomplete types are incomplete array types, or void (3.9p6). I
>cannot find anything disallowing them, unless class members are objects, in
>which case 3.9p6 disallowing declaring objects of incomplete type applies.
>
>Anthony
If class members are objects, they use memory etc. In that case, how do we
name the member 'a' in
class X{
int a;
}; ?
Clearly, X::a doesn't use memory. Therefore it can't be a class member?
Regards,
--
Michiel Salters
Consultant Technical Software Engineering
CMG Trade, Transport & Industry
Michiel.Salters@cmg.nl
---
[ 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 ]
Author: "Anthony Williams" <anthwil@nortelnetworks.com>
Date: Thu, 20 Dec 2001 19:20:15 GMT Raw View
"Michiel Salters" <Michiel.Salters@cmg.nl> wrote in message
news:Wc8U7.4688$XC5.5830@www.newsranger.com...
> In article <9vn11n$gr$1@bcarh8ab.ca.nortel.com>, Anthony Williams says...
> >
> >"Michiel Salters" <Michiel.Salters@cmg.nl> wrote in message
> >news:1n4T7.747$XC5.27@www.newsranger.com...
> >> In article <9v4iil$d4qvl$1@ID-49767.news.dfncis.de>, Anthony Williams
> >says...
> >> >
> >> >"Michiel Salters" <Michiel.Salters@cmg.nl> wrote in message
> >> >news:lN%Q7.55820$xS6.89347@www.newsranger.com...
> >> >> Is it legal to use an incomplete type (3.9 [basic.types] /6 ) as a
> >> >> class member, if no object of such class is ever created ?
[SNIP]
> >OK, agreed that 1.8 applies to objects, but 9.2p8 says:
> >
> >"Non-static (9.4) members that are class objects shall be objects of
> >previously defined classes."
> >
> >This implies that class members are objects, as how else can they be
class
> >objects?
>
> Some (most) class members are used to create objects, by creating an
object
> of the complete type. But the entire point was that we're not creating
> objects of the cmplete type.
>
> [SNIP]
>
> >The other incomplete types are incomplete array types, or void (3.9p6). I
> >cannot find anything disallowing them, unless class members are objects,
in
> >which case 3.9p6 disallowing declaring objects of incomplete type
applies.
>
> If class members are objects, they use memory etc. In that case, how do we
> name the member 'a' in
> class X{
> int a;
> }; ?
> Clearly, X::a doesn't use memory. Therefore it can't be a class member?
OK, I concede that class members are not objects unless they are members of
an object of the complete class type, as objects occupy storage and have a
lifetime, and clearly class members do not occupy storage or have lifetime
unless they are sub-objects of an object of the complete class type.
Therefore the current wording permits class members to have incomplete
types, provided no objects of the complete class type are created, which
causes other problems --- what is sizeof(Class_with_an_incomplete_member)?
Thus we need words to ban this explicitly --- how about adding words to
clause 9.2 "class members may not have incomplete type"?
Anthony
--
Anthony Williams
Software Engineer, Nortel Networks Optical Components Ltd
The opinions expressed in this message are not necessarily those of my
employer
---
[ 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 ]
Author: Michiel Salters<Michiel.Salters@cmg.nl>
Date: Sat, 22 Dec 2001 03:18:05 CST Raw View
In article <9vs90p$les$1@bcarh8ab.ca.nortel.com>, Anthony Williams says...
>
>"Michiel Salters" <Michiel.Salters@cmg.nl> wrote in message
>news:Wc8U7.4688$XC5.5830@www.newsranger.com...
>> In article <9vn11n$gr$1@bcarh8ab.ca.nortel.com>, Anthony Williams says...
>> >
>> >"Michiel Salters" <Michiel.Salters@cmg.nl> wrote in message
>> >news:1n4T7.747$XC5.27@www.newsranger.com...
>> >> In article <9v4iil$d4qvl$1@ID-49767.news.dfncis.de>, Anthony Williams
>> >says...
>> >> >
>> >> >"Michiel Salters" <Michiel.Salters@cmg.nl> wrote in message
>> >> >news:lN%Q7.55820$xS6.89347@www.newsranger.com...
>> >> >> Is it legal to use an incomplete type (3.9 [basic.types] /6 ) as a
>> >> >> class member, if no object of such class is ever created ?
>
>[SNIP]
>
>> >OK, agreed that 1.8 applies to objects, but 9.2p8 says:
>> >
>> >"Non-static (9.4) members that are class objects shall be objects of
>> >previously defined classes."
>> >
>> >This implies that class members are objects, as how else can they be
>class
>> >objects?
>>
>> Some (most) class members are used to create objects, by creating an
>object
>> of the complete type. But the entire point was that we're not creating
>> objects of the cmplete type.
>>
>> [SNIP]
>>
>> >The other incomplete types are incomplete array types, or void (3.9p6). I
>> >cannot find anything disallowing them, unless class members are objects,
>in
>> >which case 3.9p6 disallowing declaring objects of incomplete type
>applies.
>>
>> If class members are objects, they use memory etc. In that case, how do we
>> name the member 'a' in
>> class X{
>> int a;
>> }; ?
>> Clearly, X::a doesn't use memory. Therefore it can't be a class member?
>
>OK, I concede that class members are not objects unless they are members of
>an object of the complete class type, as objects occupy storage and have a
>lifetime, and clearly class members do not occupy storage or have lifetime
>unless they are sub-objects of an object of the complete class type.
>
>Therefore the current wording permits class members to have incomplete
>types, provided no objects of the complete class type are created, which
>causes other problems --- what is sizeof(Class_with_an_incomplete_member)?
>
>Thus we need words to ban this explicitly --- how about adding words to
>clause 9.2 "class members may not have incomplete type"?
>
>Anthony
And similar wording for instantiated class templates, or we can change
3.2 "T must be complete if ...".
I think it's an easy fix, though. The question remains whether we should
go hunting for redundant wording, like that class member objects must be
of complete types. I'll have a look at it before the next std meeting.
Regards,
--
Michiel Salters
Consultant Technical Software Engineering
CMG Trade, Transport & Industry
Michiel.Salters@cmg.nl
---
[ 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 ]
Author: "Anthony Williams" <anthwil@nortelnetworks.com>
Date: Tue, 18 Dec 2001 15:30:02 GMT Raw View
"Michiel Salters" <Michiel.Salters@cmg.nl> wrote in message
news:1n4T7.747$XC5.27@www.newsranger.com...
> In article <9v4iil$d4qvl$1@ID-49767.news.dfncis.de>, Anthony Williams
says...
> >
> >"Michiel Salters" <Michiel.Salters@cmg.nl> wrote in message
> >news:lN%Q7.55820$xS6.89347@www.newsranger.com...
> >> Is it legal to use an incomplete type (3.9 [basic.types] /6 ) as a
> >> class member, if no object of such class is ever created ?
> >>
> >> And as a class template member, even if the template is instantiated,
> >> but no object of the instantiated class is created?
> >>
> >> The consensus seems to be NO, but no wording was found in the standard
> >> which explicitly disallows it.
> >>
> >> The problem seems to be that most of the restrictions on incomplete
types
> >> are on their use in objects, but class members are not objects.
> >
> >Class members are objects. 1.8p2
> 1.8 applies to members of objects, not members of classes.
OK, agreed that 1.8 applies to objects, but 9.2p8 says:
"Non-static (9.4) members that are class objects shall be objects of
previously defined classes."
This implies that class members are objects, as how else can they be class
objects?
Anyway, a forward declaration does not constitute a definition, and thus a
class that is only declared is not "previously defined".
Since a class is complete at the closing brace of its class definition,
(9.2p2), all "previously defined" classes must be complete. Therefore, a
class member cannot be an incomplete class type without violating 9.2p8.
The other incomplete types are incomplete array types, or void (3.9p6). I
cannot find anything disallowing them, unless class members are objects, in
which case 3.9p6 disallowing declaring objects of incomplete type applies.
Anthony
--
Anthony Williams
Software Engineer, Nortel Networks Optical Components Ltd
The opinions expressed in this message are not necessarily those of my
employer
---
[ 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 ]