[cfe-commits] [Patch] Add -Wmissing-variable-declarations

Ed Schouten ed at 80386.nl
Thu Dec 15 07:47:07 PST 2011


Hi Eli,

* Eli Friedman <eli.friedman at gmail.com>, 20111210 03:38:
> The check should be in CheckCompleteVariableDeclaration, not
> CheckVariableDeclaration.

Are you sure about this? If I place it in CheckCompleteVariable-
Declaration, I can only emit warnings when saying:

	int i = 3;

Not:

	int i;

The intention is that even a regular `int i' generates a compiler
warning. It must be preceded by `extern int i'.

> isThisDeclarationADefinition() to check for a definition, and
> getLinkage() to check whether the declaration is externally visible.
> (The one interesting C testcase here is "extern int x = 3;"; there are
> also various C++ tests of interest, like const globals and a
> definition in an anonymous namespace.)

I'm not a very good compiler hacker so I could use some help here. I
suspect you mean something like this?

  if (var->isThisDeclarationADefinition() &&
      var->getLinkage() == ExternalLinkage &&
      var->getPreviousDeclaration() == NULL)
    Diag(var->getLocation(),
      diag::warn_missing_variable_declarations) << var;

Thanks,
-- 
 Ed Schouten <ed at 80386.nl>
 WWW: http://80386.nl/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20111215/a316ee12/attachment.sig>


More information about the cfe-commits mailing list