Member initialization of arrays of constants
Michael Schwendt
mschwendt@web.de
Wed Jul 26 01:04:00 GMT 2000
On Tue, 25 Jul 2000 llewelly@dbritsch.dsl.xmission.com wrote:
>I think we should move this discussion to comp.std.c++ .
Of course. I'll consider that depending on a reply from Borland's support (if any).
>> Error: Constant member 'A::c' in class without constructors
>
>I cannot find wording in the standard that disallows const members
> from classes without constructors.
>
>(Nor have I ever found a C++ compiler that did not have a multitude of
> bugs.)
Me neither. However, I find errors like this in commercial and popular compilers disgusting. I mean, I can't be the only one who has tried to port code which uses an aggregate with constant members as a character-based binary file header. On the other hand, a lot of C/C++ programmers seem to not like const-qualified types. So, most likely they work with non-consts in most places. ;-)
>> struct A
>> {
>> const char c[4];
>> const j;
>
>I presume 'const j' was intended to be 'const int j' .
Yes, a typo.
>I do think 12.6.1/4 makes this constructor ill-formed, however, your
> previous examples did not contain user-defined constructors, and
> were aggregates according to 8.5.1; this class is not.
Ack. I had tried a few alternatives. The most trivial one would be to remove all const's from the structure and make sure read-only values are not written to. This would be feasible, but hey, that const-portability issue bugs me.
>(gcc 2.95.2, and 2.96 20000626 both compile it without errors, and
> that (I belive) *is* a bug, but it is different from your earlier
> examples.)
Ack.
[snip]
>In your 'Example 2', the initialization was not in the class
> declaration, and so I do not see how 9.2/4 applies.
Forget about it, please. What I had in mind was extending an aggregate to become a non-aggregate by adding constructors. Doing that, the new non-aggregate class would suffer a lot from lack of flexibility compared with the old aggregate. This move would force me to turn member aggregates static, and I'd also need to redesign a lot of other code because I couldn't initialize sub-aggregate arrays of constants easily.
<off-topic>
>> Yes. Whenever I add a constructor, I can forget about using the
>> brace-enclosed initializer-list. Hmmm...
>
>That is what 8.5.1/1 says.
This is where this entire issue turns out to get nasty.
>From this nice and *simple* aggregate
struct A1
{
const char a[4];
char b[4];
// add members here
};
to
struct A2
{
const char a[4];
char b[4];
// add members here
A(const char*) // error! ctor makes member 'a' illegal!
{ ; }
};
Hmm... =:-}
</off-topic>
Case closed. *g*
Regards,
Mike
_______________________________________________________________________
1.000.000 DM gewinnen - kostenlos tippen - http://millionenklick.web.de
IhrName@web.de, 8MB Speicher, Verschluesselung - http://freemail.web.de
More information about the Gcc-bugs
mailing list