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

Eli Friedman eli.friedman at gmail.com
Wed Aug 1 13:08:59 PDT 2012

On Tue, Jul 24, 2012 at 7:06 AM, Ed Schouten <ed at 80386.nl> wrote:
> Hi Eli,
> 2012/6/21 Eli Friedman <eli.friedman at gmail.com>:
>> Ah... looks like we don't call it for tentative definitions (which we
>> handle in Sema::ActOnEndOfTranslationUnit).  This has no effect for
>> the existing checks in CheckCompleteVariableDeclaration because none
>> of them apply to global variables in C.  That could easily be changed,
>> though.
> Gotcha! Thanks for the pointer.
>> Actually, you might want some special handling for tentative
>> definitions.  What do you expect the warning to do for a testcase like
>> "int x; int x = 10;"?
> Well, effectively I want to do the same as C++: int x must always be
> preceded by extern int i, which is typically placed in a header file.
>> I think it just got renamed to getPreviousDecl().
> Got it.
> I've updated the patch. As usual, it can be downloaded from:
> http://80386.nl/pub/wmissing-variable-declarations.txt

@@ -6839,8 +6839,10 @@

       // Record the tentative definition; we're done.
-      if (!Var->isInvalidDecl())
+      if (!Var->isInvalidDecl()) {
+        CheckCompleteVariableDeclaration(Var);
+      }

Calling CheckCompleteVariableDeclaration here doesn't make sense; the
variable isn't complete at this point.  If we're going to call it, it
should be from Sema::ActOnEndOfTranslationUnit.

Otherwise, looks fine.


More information about the cfe-commits mailing list