[cfe-dev] warning request: partial array initialisation

David Blaikie dblaikie at gmail.com
Tue Jun 19 08:33:40 PDT 2012


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
>
> This would be useful because we have a large codebase where N is
> defined in some common header and there are lots of arrays of length N
> scattered through the code. Occasionally someone increments N, but
> forgets to update all the array initialisers (because it's hard to
> find them).
>
> I'm not sure what heuristics should be used to define "almost all".
>
> Can clang or some static analyser already do this? "clang -Wall
> -Wextra" doesn't seem to warn about it.

Just as a side note: if you want to check if Clang has any diagnostics
for a piece of code, you can use "-Weverything" to turn on /all/ Clang
diagnostics.

- David




More information about the cfe-dev mailing list