Topic: Defect Report: Restrictions on use of incomplete types not complete?


Author: Michiel Salters<Michiel.Salters@cmg.nl>
Date: Mon, 17 Dec 2001 15:52:45 GMT
Raw View
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...
>> [Moderator's note: this defect report has been
>> forwarded to the C++ committee. -moderator.]
>>
>> Question:
>>
>> 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 says:
>
>"Objects can contain other objects, called sub-objects. A sub-object can be
>a member sub-object (9.2), a base class sub-object (clause 10), or an array
>element. An object that is not a sub-object of any other object is called a
>complete object."

1.8 applies to members of objects, not members of classes.

E.g.
class X {
int a;
};

X x;

Now X::a is a class member, not an object.
x is an object, and x.a is a sub-object of it. But that wasn't the issue.

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: Michiel Salters<Michiel.Salters@cmg.nl>
Date: 11 Dec 01 00:57:27 GMT
Raw View
 [Moderator's note: this defect report has been
 forwarded to the C++ committee. -moderator.]

Question:

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.

A possible resolution, if this is considered a defect, is to add to
3.2 [basic.def.odr] /4 , ( situations when T must be complete ), the
use of T as a member of a class or instantiated class template.

The thread on comp.std.c++ which brought up the issue was
"Compiler differences: which is correct?", started 2001 11 30.
<3c07c8fb$0$8507$ed9e5944@reading.news.pipex.net>

--
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, 11 Dec 2001 16:00:49 GMT
Raw View
"Michiel Salters" <Michiel.Salters@cmg.nl> wrote in message
news:lN%Q7.55820$xS6.89347@www.newsranger.com...
> [Moderator's note: this defect report has been
> forwarded to the C++ committee. -moderator.]
>
> Question:
>
> 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 says:

"Objects can contain other objects, called sub-objects. A sub-object can be
a member sub-object (9.2), a base class sub-object (clause 10), or an array
element. An object that is not a sub-object of any other object is called a
complete object."

> A possible resolution, if this is considered a defect, is to add to
> 3.2 [basic.def.odr] /4 , ( situations when T must be complete ), the
> use of T as a member of a class or instantiated class template.
>
> The thread on comp.std.c++ which brought up the issue was
> "Compiler differences: which is correct?", started 2001 11 30.
> <3c07c8fb$0$8507$ed9e5944@reading.news.pipex.net>


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: jthill_@mac.com (Jim Hill)
Date: Wed, 12 Dec 2001 02:03:59 GMT
Raw View
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 ?

> The consensus seems to be NO, but no wording was found in the standard
> which explicitly disallows it.

Ah. I think 9.2p8 was trying to say that:
| Non-`static` (9.4) members that are class objects shall be objects
| of previously defined classes.

but shouldn't have used "objects".  I think it's clear as it stands,
but it's so fundamental I doubt I can read it without bias.  So I
propose an alternate resolution: replace that first sentence of 9.2p8
with

| If the 'decl-specifier-seq' of a data member 'declarator' specifies
| an incomplete, non-`static` type, the declarator shall begin with a
| 'ptr-operator'.

Jim

---
[ 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                ]