Too many initializers error for a simple array in bcc32
Asked Answered
S

1

4

Compiling the following example

struct S {};

int main() {
  S array[1] = { S() };
}

with bcc32 I get the following error:

[bcc32 Error] test.cpp(4): E2225 Too many initializers

Is it a bug in bcc32 or am I missing something and the above example is not valid C++?

Both Clang and GCC compile this example without problems.

Stickweed answered 20/11, 2015 at 15:9 Comment(4)
Seems perfectly valid aggregate initialization to me. I'm not sure if it's the problem here, but I think using S() in there wouldn't be technically correct before c++03. Does bcc32 support c++03?Culvert
They claim to support some of the C++11 features such as rvalue references but I couldn't find information about the completeness of C++98/03 support.Stickweed
The feature that's needed from c++03 to make that technically correct is value-initialization. I'd be very surprised if the compiler didn't support it if it does support C++11 too. Besides, I'm not sure how that applies to an empty object because the technicality is related to copying the object but there is nothing to copy.Culvert
@Stickweed see my answer how to solve this...Virtuoso
V
3

Borland BDS2006 (and possibly newer versions)

has some issues with default constructor/destructor for class and struct inside its C++ engine.

Adding custom (even empty) constructor/destructor solves many issues even yours. Try:

struct S
    {
    S(){};
    S(S& a){};
    ~S(){};
    S* operator = (const S *a){};
    //S* operator = (const S &a){}; // use this only if you have dynamic allocation members
    };

int main()
    {
    S array[1] = { S() };
    }

I tried this in BDS2006 and it looks like it works (hard to tell without anything inside struct) but you can compile and run at least...

I detect this behavior first in BDS2006 ... haven't really try BCB6 as it was junk from the start and dismiss it after few days (I think the worst BCB ever even beats BCB3,4) in BCB5 was all fine (before BDS2006 was this my favorite IDE) with this so they must have change the C++ engine (do not confuse with runtime libs !!!).

Adding even empty constructor destructor helps. If you got dynamic allocations you need to handle those of coarse. If you got nested class/struct do not forget to add these also to them too.

Virtuoso answered 23/11, 2015 at 9:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.