This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [c++] RFC: partial C99 designated-initializers support

Mark Mitchell wrote:
Bernardo Innocenti wrote:

Richard Henderson wrote:

On Fri, Oct 22, 2004 at 11:47:49PM +0200, Bernardo Innocenti wrote:

Bootstrapped and not tested as this will have to wait for
4.1 anyway.

It definitely doesn't work.  I'd written all of the parsing bits
once, until I stumbled upon the fact that the front end doesn't
even support the gnu extension properly -- it doesn't support
having the fields specified out of order.  Which is basically
the whole point.

Out-of-order initializers are checked for in process_init_constructor(), with a sorry("non-trivial labeled initializers"). Would that be easy to fix? And would it be welcome?

What does C99 say should happen in this case:

int i[] = { [3] = 7, [2] = i[3] };

Our C parser likes it and I can see no test for it in gcc.dg/c99-init-2.c.

? In C++, it would be wrong to actually initialize the elements of an array/structure in anything other than the order in which they are declared, as otherwise the destructors for elements would not be run in the reverse order of construction. So, I'm concerned about the possibility that the same code might not mean the same thing in C and in C++.

For member initializers in constructors, we silently reorder the initialization (the warning is only enabled with -Wall).

struct A {
       int first, second;
       A() : second(0), first(second) { /*nop*/ }

Maybe we could do the same for the C99 syntax, except that the warning would be always enabled since this behavior is not specified by the standard.

Aside from that concern, I think it's a matter of only moderately much work to make labeled initializers work in C++. I think it would be welcome, despite the fact that is not part of ISO C++, because, generally, we're trying to support C99 in C++. Other C++ maintainers might have other opinions, though.

I'll see if I can do that on my own, but I'm not familiar at all with the C++ frontend. I can see how the C frontend does it and maybe I'll ask for janitorial help.

BTW, the reason I want this in the C++ frontend is that we're doing embedded development in C for AVR and other small processors, but sometimes we'd like to use C++ features such as templates and destructors. The C++ frontend parses our C sources very well except for those C99 initializers.

 // Bernardo Innocenti - Develer S.r.l., R&D dept.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]