-Wmissing-variable-declaration

Hi all,

Before I start, IANACH (I Am Not A Compiler Hacker), so don't blame me
if my code is horrible.

Something I've noticed in large code bases (e.g. FreeBSD), is that even
though people use compiler flags like -Wmissing-prototypes and fix their
code accordingly, the same type of problem exists for global variables.
This could in theory cause certain optimisations to be missed, but it
also causes namespace issues.

So my idea would be to have a compiler flag that would cause Clang to
generate a warning for this. So for example:

Good:

  static int i;
  extern int j;
  int j;

Bad:

  int k;

Attached is a patch that adds a new warning flag called
-Wmissing-variable-declaration that implements this behaviour. Any
comments?

missing-variable-declaration.diff (1.59 KB)

Hi Ed,

I cannot comment on the code or if this is regarded useful, but you should definitely include a test case in your patch.

Tobi

Hi Tobias,

* Tobias Grosser <tobias@grosser.es>, 20111028 21:53:

I cannot comment on the code or if this is regarded useful, but you
should definitely include a test case in your patch.

Sure. I've attached a new patch, which renames the compiler switch to
-Wmissing-variable-declarations (plural, like the other -Wmissing-*
flags). This patch also adds testcases that pass the testsuite on my
system.

Thanks,

missing-variable-declarations.diff (2.07 KB)