summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorAaron Puchert <aaron.puchert@sap.com>2019-06-18 22:57:08 +0000
committerAaron Puchert <aaron.puchert@sap.com>2019-06-18 22:57:08 +0000
commitdf195d8aedffa9211f37db7fd08f46adf41386f0 (patch)
tree767829914b4b67f34dca763c646b1eee15a14412 /clang/lib/Sema/SemaDecl.cpp
parentf9c6e565de2a9e8d596c6ea16c4a7b11c870b720 (diff)
downloadbcm5719-llvm-df195d8aedffa9211f37db7fd08f46adf41386f0.tar.gz
bcm5719-llvm-df195d8aedffa9211f37db7fd08f46adf41386f0.zip
Suggestions to fix -Wmissing-{prototypes,variable-declarations}
Summary: I've found that most often the proper way to fix this warning is to add `static`, because if the code otherwise compiles and links, the function or variable is apparently not needed outside of the TU. We can't provide a fix-it hint for variable declarations, because multiple VarDecls can share the same type, and if we put static in front of that, we affect all declared variables, some of which might have previous declarations. We also provide no fix-it hint for the rare case of an `extern` function definition, because that would require removing `extern` and I have no idea how to get the source location of the storage class specifier from a FunctionDecl. I believe this information is only available earlier in the AST construction from DeclSpec::getStorageClassSpecLoc(), but we don't have that here. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D59402 llvm-svn: 363749
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e92c3d0a19a..03b6cc91657 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11899,8 +11899,11 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
while (prev && prev->isThisDeclarationADefinition())
prev = prev->getPreviousDecl();
- if (!prev)
+ if (!prev) {
Diag(var->getLocation(), diag::warn_missing_variable_declarations) << var;
+ Diag(var->getTypeSpecStartLoc(), diag::note_static_for_internal_linkage)
+ << /* variable */ 0;
+ }
}
// Cache the result of checking for constant initialization.
@@ -13364,6 +13367,13 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
? FixItHint::CreateInsertion(FTL.getRParenLoc(), "void")
: FixItHint{});
}
+ } else {
+ Diag(FD->getTypeSpecStartLoc(), diag::note_static_for_internal_linkage)
+ << /* function */ 1
+ << (FD->getStorageClass() == SC_None
+ ? FixItHint::CreateInsertion(FD->getTypeSpecStartLoc(),
+ "static ")
+ : FixItHint{});
}
// GNU warning -Wstrict-prototypes
OpenPOWER on IntegriCloud