Topic: POD-Struct Aggregate Initialization
Author: Alexis Layton <alex@inconcert.com>
Date: 1997/07/29 Raw View
A problem came up recently while I was working on a program. A dumb
simplification boils down to the following. Sun's SC4.0 and SC4.2
compilers, as well as HP's aCC seem to give the same error,
but my reading of the December '96 DWP would seem to indicate otherwise.
Given oog.cc:
enum X {
one,
two,
three
};
struct A {
int i;
X x;
};
struct B {
A a1;
A a2;
int z;
};
A a_1 = { 1, one };
A a_2 = { 2, two };
B b = { a_1, a_2, 4 }; // here
the SC4.2 compiler (and others) claim
"oog.cc", line 20: Error: Cannot use A to initialize int.
"oog.cc", line 20: Warning (Anachronism): Using A to initialize X.
"oog.cc", line 20: Note: Type "CC -migration" for more on anachronisms.
"oog.cc", line 20: Error: Cannot use A to initialize X.
2 Error(s) and 1 Warning(s) detected.
Now, I read this as using an A to initialize an A, so I am a bit
perplexed.
The critical question boils down to whether the words "recursively" in
8.5.1 clause 2 applies only to that clause or to 8.5.1 as a whole.
If it applies to 8.5.1 as a whole, then by clause 3 the recursize
invocation
of the initialization of the subaggregate can be by a single expression
(a_1).
Even if the language does not permit that reading, I would argue that
clause
12 second sentence applies -- the initializer (a_1) can intialize the
member
B::a1 using the trivial copy constructor. Is this not the case?
Perplexed,
--
Alexis Layton InConcert Incorporated,
Sr. Software Engineer A Xerox New Enterprises Company
alex@InConcertSW.COM Four Cambridge Center
+1 617 499-4443 Cambridge, MA 02142-1494
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]