]> granicus.if.org Git - clang/commitdiff
PR35862: Suppress -Wmissing-variable-declarations warning on inline variables,
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 8 Jan 2018 21:46:42 +0000 (21:46 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 8 Jan 2018 21:46:42 +0000 (21:46 +0000)
variable templates, and instantiations thereof.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322030 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/warn-missing-variable-declarations.cpp

index 24ed78c8bfd8f7dce40e3cd8ff673a92a6fc824e..23fcfb4ec7ca83c8494e8e9c82e2cd44ffeeb7c1 100644 (file)
@@ -11348,6 +11348,8 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
   if (var->isThisDeclarationADefinition() &&
       var->getDeclContext()->getRedeclContext()->isFileContext() &&
       var->isExternallyVisible() && var->hasLinkage() &&
+      !var->isInline() && !var->getDescribedVarTemplate() &&
+      !isTemplateInstantiation(var->getTemplateSpecializationKind()) &&
       !getDiagnostics().isIgnored(diag::warn_missing_variable_declarations,
                                   var->getLocation())) {
     // Find a previous declaration that's not a definition.
index 5b882845f3c6e31fc85acd73def551d108521c32..5b71f38c811f0c0f49f1ecd27da4004489ee3002 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang -Wmissing-variable-declarations -fsyntax-only -Xclang -verify %s
+// RUN: %clang -Wmissing-variable-declarations -fsyntax-only -Xclang -verify -std=c++17 %s
 
 // Variable declarations that should trigger a warning.
 int vbad1; // expected-warning{{no previous extern declaration for non-static variable 'vbad1'}}
@@ -52,3 +52,24 @@ class C {
 namespace {
   int vgood4;
 }
+
+inline int inline_var = 0;
+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}}
+extern constexpr int extern_constexpr_var = 0; // expected-warning {{no previous extern declaration}}
+
+template<typename> int var_template = 0;
+template<typename> constexpr int const_var_template = 0;
+template<typename> static int static_var_template = 0;
+
+template int var_template<int[1]>;
+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}}
+
+// 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}}