Topic: List initialization of aggregate containing class...


Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1998/11/02
Raw View
On Nov  2, 1998, clamage@Eng.Sun.COM (Steve Clamage) wrote:

> "Jim Sievert" <jas1@rsvl.unisys.com> writes:
>> From what I've seen, an aggregate is defined as an array, class, or
>> structure type which:

>> o  Has no constructors.
>> o  Has no nonpublic members.
>> o  Has no base classes.
>> o  Has no virtual functions.

> You forgot that any subobjects must also be aggregates.
> See 8.5.1 "Aggregates", paragraph 2.

It only talks about the way aggregates can be initialized with a
brace-enclosed list.  Members of PODs can only be PODs, but this does
not apply to aggregates too, AFAIK.  Although [dcl.init.aggr]/13 is
only a Note, it clearly implies that aggregates may contain members of
class types with user-declared constructors, that are not aggregates.

--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:oliva@gnu.org mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Christopher M. Gurnee" <gurnec_at_mediaone_dot_net@127.0.0.1>
Date: 1998/11/02
Raw View
Steve Clamage wrote in message <71ct0d$ff6$1@engnews1.eng.sun.com>...
>"Jim Sievert" <jas1@rsvl.unisys.com> writes:
>
>>From what I've seen, an aggregate is defined as an array, class, or
>>structure type which:
>
>>o  Has no constructors.
>>o  Has no nonpublic members.
>>o  Has no base classes.
>>o  Has no virtual functions.
>
>You forgot that any subobjects must also be aggregates.
>See 8.5.1 "Aggregates", paragraph 2.
<clip>

This paragraph only applies to subobjects that recursively use
brace-enclosed lists for initialization, as in the example in that
paragraph.  AFAIK, there is no special restriction on the type of a
subobject in an aggregate.  12.6.1/2  has details on how such members
are initialized.  Jim Sievert:  your example should work as is.

-Chris Gurnee





[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Jim Sievert" <jas1@rsvl.unisys.com>
Date: 1998/11/02
Raw View

Steve Clamage wrote in message <71ct0d$ff6$1@engnews1.eng.sun.com>...
>
>You forgot that any subobjects must also be aggregates.
>See 8.5.1 "Aggregates", paragraph 2.
>

I did not get this from reading P2.  P2 talks to initializing aggregates
containing subaggregates:

2 When an aggregate is initialized the initializer can be an initializer=AD
clause consisting of a brace=AD enclosed,
comma=AD separated list of initializers for the members of the aggregate,
written in increasing subscript or
member order. If the aggregate contains subaggregates, this rule applies
recursively to the members of the
subaggregate. [Example:


struct A

int x;
struct B

int i;
int j;
} b;
} a =3D { 1, { 2, 3 } };


initializes a. x with 1, a. b. i with 2, a. b. j with 3. ]




[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Jim Sievert" <jas1@rsvl.unisys.com>
Date: 1998/11/02
Raw View

Alexandre Oliva wrote in message ...
>They're wrong.  It is an aggregate; [dcl.init.aggr] says:
>
>13[Note: An aggregate array or an aggregate class may contain members of
>  a  class  type  with a user-declared constructor
>


I used P13 above as an argument to MS.  They admit to this bug in their
compiler.  The actual wording of the standard was important to them agreeing
that there is a problem.  The specific wording "user-declared constructor"
was the important phrase.  It seems that their compiler implementation
generated a constructor for the aggregate in order to do the initialization.
In talking with MS support, it seems that if the standard had read something
like "...may contain members of a class type with a constructor...", I might
of had a much more difficult case to prove.

Thanks for the feedback...



[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1998/11/02
Raw View
"Jim Sievert" <jas1@rsvl.unisys.com> writes:

>From what I've seen, an aggregate is defined as an array, class, or
>structure type which:

>o  Has no constructors.
>o  Has no nonpublic members.
>o  Has no base classes.
>o  Has no virtual functions.

You forgot that any subobjects must also be aggregates.
See 8.5.1 "Aggregates", paragraph 2.

>class Ca
>{
>public:
>   Ca( int x );
>   Ca( const Ca & );
>...
>};

>struct Sa
>{
>   Ca m_a;
>};

Since Ca is not an aggregate, neither is Sa.


--
Steve Clamage, stephen.clamage@sun.com
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1998/11/02
Raw View
On Oct 29, 1998, "Jim Sievert" <jas1@rsvl.unisys.com> wrote:

> struct Sa { Ca m_a; };

> I believe that Sa is an aggregate given the above definition.

Correct.

> Sa sa = { Ca( 10 ) };

> The MS compilers (5.0 and 6.0) are rejecting 'sa' saying that it's not an
> aggregate.

They're wrong.  It is an aggregate; [dcl.init.aggr] says:

13[Note: An aggregate array or an aggregate class may contain members of
  a  class  type  with a user-declared constructor

--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:oliva@gnu.org mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Nate Lewis" <nlewis@mindspring.com>
Date: 1998/11/02
Raw View
Steve Clamage wrote in message <71ct0d$ff6$1@engnews1.eng.sun.com>...
>"Jim Sievert" <jas1@rsvl.unisys.com> writes:
>
>>From what I've seen, an aggregate is defined as an array, class, or
>>structure type which:
>
>>o  Has no constructors.
>>o  Has no nonpublic members.
>>o  Has no base classes.
>>o  Has no virtual functions.
>
>You forgot that any subobjects must also be aggregates.
>See 8.5.1 "Aggregates", paragraph 2.

As I read that paragraph, 'this rule' clearly means 8.5.1/2, not 8.5.1/1
or even 8.5.1; it describes nesting of braced initializer lists and does
not change the complete (?) definition of an aggregate in paragraph 1.
"If the aggregate contains subaggregates, this rule applies recursively"
would be paradoxical, if it did.  The example reinforces this; as
Alexandre notes, so does 8.5.1/13.

This isn't the first time this question has come up, but I haven't seen
it resolved; your understanding appears to be the most common, but I
can't see why.  (Whether it says what it was meant to say is another
discussion; I'm guessing not, judging by the confusion.)

--
Nate Lewis, MCSD
nlewis@mindspring.com
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Jim Sievert" <jas1@rsvl.unisys.com>
Date: 1998/10/29
Raw View