diff options
author | ed <ed@FreeBSD.org> | 2012-10-25 10:13:58 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2012-10-25 10:13:58 +0000 |
commit | be7b7f088b806d1ea94647b4427a35dc0ef6daed (patch) | |
tree | c7cf2e42166e846ecbead16b0cbf1e94154ebded /contrib/llvm/tools/clang/lib/Sema | |
parent | 71112b5a8eb3a8cd3f5d49eff9664a32fec42b56 (diff) | |
download | FreeBSD-src-be7b7f088b806d1ea94647b4427a35dc0ef6daed.zip FreeBSD-src-be7b7f088b806d1ea94647b4427a35dc0ef6daed.tar.gz |
Pull in r166498 from upstream clang trunk:
Add a new warning -Wmissing-variable-declarations, to warn about variables
defined without a previous declaration. This is similar to
-Wmissing-prototypes, but for variables instead of functions.
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Sema')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Sema/Sema.cpp | 2 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp | 11 |
2 files changed, 13 insertions, 0 deletions
diff --git a/contrib/llvm/tools/clang/lib/Sema/Sema.cpp b/contrib/llvm/tools/clang/lib/Sema/Sema.cpp index 7f79f0c..6e2de4d 100644 --- a/contrib/llvm/tools/clang/lib/Sema/Sema.cpp +++ b/contrib/llvm/tools/clang/lib/Sema/Sema.cpp @@ -648,6 +648,8 @@ void Sema::ActOnEndOfTranslationUnit() { diag::err_tentative_def_incomplete_type)) VD->setInvalidDecl(); + CheckCompleteVariableDeclaration(VD); + // Notify the consumer that we've completed a tentative definition. if (!VD->isInvalidDecl()) Consumer.CompleteTentativeDefinition(VD); diff --git a/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp b/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp index ea181de..ff1eb84 100644 --- a/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp +++ b/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp @@ -6957,6 +6957,17 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) { } } + if (var->isThisDeclarationADefinition() && + var->getLinkage() == ExternalLinkage) { + // Find a previous declaration that's not a definition. + VarDecl *prev = var->getPreviousDecl(); + while (prev && prev->isThisDeclarationADefinition()) + prev = prev->getPreviousDecl(); + + if (!prev) + Diag(var->getLocation(), diag::warn_missing_variable_declarations) << var; + } + // All the following checks are C++ only. if (!getLangOpts().CPlusPlus) return; |