[cfe-commits] [Patch] Add -Wmissing-variable-declarations
eli.friedman at gmail.com
Thu Dec 15 08:47:20 PST 2011
On Thu, Dec 15, 2011 at 7:47 AM, Ed Schouten <ed at 80386.nl> wrote:
> Hi Eli,
> * Eli Friedman <eli.friedman at gmail.com>, 20111210 03:38:
>> The check should be in CheckCompleteVariableDeclaration, not
> Are you sure about this? If I place it in CheckCompleteVariable-
> Declaration, I can only emit warnings when saying:
> int i = 3;
> int i;
> The intention is that even a regular `int i' generates a compiler
> warning. It must be preceded by `extern int i'.
I'm pretty sure we call CheckCompleteVariableDeclaration for both
those declarations; I could be mistaken, though.
>> 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::warn_missing_variable_declarations) << var;
More information about the cfe-commits