[cfe-dev] warning request: partial array initialisation

Chandler Carruth chandlerc at google.com
Tue Jun 19 10:57:59 PDT 2012


On Tue, Jun 19, 2012 at 10:50 AM, Jay Foad <jay.foad at gmail.com> wrote:

> On 19 June 2012 17:49, Chandler Carruth <chandlerc at google.com> wrote:
> > On Tue, Jun 19, 2012 at 1:20 AM, Jay Foad <jay.foad at gmail.com> wrote:
> >>
> >> Hi,
> >>
> >> I'd really like to be able to get a warning when "almost all" elements
> >> of an array are initialised:
> >>
> >>  #define N 8
> >>  const int a[N] = { 3, 1, 4, 1, 5, 9, 2 };
> >>  warning: some but not all array elements initialised
> >
> >
> > At least in C++, this warning wouldn't make a lot of sense because all of
> > the array elements *are* initialized. [dcl.init.aggr] 8.5.1/7: "If there
> are
> > fewer initializers in the list than there are members in the aggregate,
> then
> > each member not explicitly initialized shall be value-initialized (8.5)."
>
> OK, so pretend the warning said "some but not all array elements
> explicitly initialised".
>
> I realise that this construct is well defined (like most other
> constructs that compilers warn about). I'd still like to be warned
> about it, because it's slightly suspicious. I'm not suggesting that
> the warning should be on by default, or included in -Wall, or anything
> like that.


We'd like to avoid warnings that don't catch enough bugs and have
reasonable enough alternatives to end up eventually under '-Wall'. Having
an off-by-default warning slows down the compiler and tends to cause the
code to rot.

Also, this seems really like a coding convention or style you would like to
enforce, and so I suspect a separate tool would be better suited to it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120619/399fa620/attachment.html>


More information about the cfe-dev mailing list