This is the mail archive of the gcc-bugs@gcc.gnu.org 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]

[Bug c++/55805] Empty brace-init-list causes warning "missing initializer for member" in C++11


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55805

--- Comment #7 from Gubbins <dave.gittins at gmail dot com> ---
(In reply to Gubbins from comment #6)
> (In reply to Jonathan Wakely from comment #3)
> > (In reply to Gubbins from comment #2)
> > > The original bug report points that in C++11 this is *not* aggregate
> > > initialization, but is in fact value initialization (because this is a class
> > > type with a default constructor).
> > 
> > No it isn't, it's an aggregate.
> 
> It's clear that A is an aggregate type, but it is also a class type with a
> default constructor. Doesn't the quoted section of the C++11 specification
> therefore state that the object should be value-initialized?

Anyway, even if this is classified as aggregate initialization (which I believe
it is in C++14?), I believe the behaviour should be changed. The distinction
between value-initializing a class and aggregate-initializing it with zero
field initializers is not a useful one here, IMHO - it's more of a
technicality. The result is the same either way (if we, say, add a base class
to A in the example then A is no longer aggregate and we get the same
initialization outcome with no warning). The current warning behaviour is an
annoyance that means I either need to disable -Wmissing-field-initializers (I
prefer to keep it enabled) or initialize my object in a more long-winded way.

Coming at it the other way, the point of the warning is presumably to catch
errors in which the user accidentally supplies only N initializers for M
fields, which is good. I'd suggest that when N=0, it's very unlikely to be an
accident!

I propose that the missing-field-initializers warning should not apply to empty
aggregate initialization lists, but a separate (new) warning
-Wempty-field-initializers could be added which warns for such empty lists if
your class happens to be aggregate.


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