summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/warn-missing-variable-declarations.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/test/SemaCXX/warn-missing-variable-declarations.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/test/SemaCXX/warn-missing-variable-declarations.cpp')
-rw-r--r--clang/test/SemaCXX/warn-missing-variable-declarations.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/warn-missing-variable-declarations.cpp b/clang/test/SemaCXX/warn-missing-variable-declarations.cpp
index 5b71f38c811..e2480fd663b 100644
--- a/clang/test/SemaCXX/warn-missing-variable-declarations.cpp
+++ b/clang/test/SemaCXX/warn-missing-variable-declarations.cpp
@@ -1,11 +1,15 @@
-// RUN: %clang -Wmissing-variable-declarations -fsyntax-only -Xclang -verify -std=c++17 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-variable-declarations -std=c++17 %s
// Variable declarations that should trigger a warning.
int vbad1; // expected-warning{{no previous extern declaration for non-static variable 'vbad1'}}
+// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}
+
int vbad2 = 10; // expected-warning{{no previous extern declaration for non-static variable 'vbad2'}}
+// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}
namespace x {
int vbad3; // expected-warning{{no previous extern declaration for non-static variable 'vbad3'}}
+ // expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}
}
// Variable declarations that should not trigger a warning.
@@ -58,7 +62,9 @@ const int const_var = 0;
constexpr int constexpr_var = 0;
inline constexpr int inline_constexpr_var = 0;
extern const int extern_const_var = 0; // expected-warning {{no previous extern declaration}}
+// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}
extern constexpr int extern_constexpr_var = 0; // expected-warning {{no previous extern declaration}}
+// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}
template<typename> int var_template = 0;
template<typename> constexpr int const_var_template = 0;
@@ -69,7 +75,9 @@ int use_var_template() { return var_template<int[2]>; }
template int var_template<int[3]>;
extern template int var_template<int[4]>;
template<> int var_template<int[5]>; // expected-warning {{no previous extern declaration}}
+// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}
// FIXME: We give this specialization internal linkage rather than inheriting
// the linkage from the template! We should not warn here.
template<> int static_var_template<int[5]>; // expected-warning {{no previous extern declaration}}
+// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}
OpenPOWER on IntegriCloud