Description of Problem:
Fails to compile what I believe is valid code. A *declaration* for an
array without size specified is being treated like a trailing empty array
structure member declaration, i.e. treated as though it were size one. A
later *definition* of the array with initialisers is treated as an error.
Code that fails to compile:
int const foo[];
int main (int ac, char **av) { int const *ip = foo; return 0; }
int const foo[] = { 3, 2, 1, 0 };
Version-Release number of selected component (if applicable):
gcc-3.1-0.10
How Reproducible:
Try to compile the above ...
Actual Results:
[bill@desktop tmp]$ c++ -o Bug Bug.C
Bug.C:2: uninitialized const `foo'
Bug.C:2: array size missing in `foo'
Bug.C:4: redefinition of `const int foo[]'
Bug.C:2: `const int foo[1]' previously declared here
Bug.C:4: excess elements in aggregate initializer
[bill@desktop tmp]$
Expected Results:
[bill@desktop tmp]$ /usr/bin/i386-redhat-linux7-c++ -o Bug Bug.C
[bill@desktop tmp]$
Additional Information:
Strictly guesswork territory here, but is this to do with allowing an empty
array to be declared as the last member of a structure (the variable-size
hack) ?
I know that compiling with a previous version proves nothing, but this does
work with 2.96 :o) and is valid according to the grammar in the back of
Stroustrup [3rd].

OK, it should have been the "gcc-c++" package up there ...
If this is actually violating the ANSI standard I'd like to know; it doesn't
look like it. Basically that error should only be issued if *by the end of the
translation unit* the array type has not been completed. Since the element type
(int) is complete, it should not be an error to index the array in main(); the
incomplete declaration should be equivalent to "extern const int foo[]" (which
is accepted).

OK *shrug*
I know it's valid C ... I couldn't find anything to explain why it should have
become illegal in C++. Must have missed something. If you happen to know where
in the standard this is standardized (I went through a lot of stuff that Google
turned up, and the only impression I came away with was that this ought to be
fine ...) I'd appreciate someone telling me. One day I might get to read the
thing.

Oh well ... chalk one up to experience. Most of the other things which have
caught me out have been obvious violations of something. I couldn't find any
reference to this in Stroustrup ... anyway, now, like Coleridge's wedding guest,
I am a sadder and wiser man ;o)

Note

You need to
log in
before you can comment on or make changes to this bug.