From 2f27999df400d17b33cdd412fdd606a88208dfcc Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Thu, 31 May 2018 04:15:13 +0000 Subject: Merging r322030: ------------------------------------------------------------------------ r322030 | rsmith | 2018-01-08 13:46:42 -0800 (Mon, 08 Jan 2018) | 3 lines PR35862: Suppress -Wmissing-variable-declarations warning on inline variables, variable templates, and instantiations thereof. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_60@333623 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 2 ++ .../SemaCXX/warn-missing-variable-declarations.cpp | 23 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7ca48c34e5..0ceaf7c6d6 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -10947,6 +10947,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. diff --git a/test/SemaCXX/warn-missing-variable-declarations.cpp b/test/SemaCXX/warn-missing-variable-declarations.cpp index 5b882845f3..5b71f38c81 100644 --- a/test/SemaCXX/warn-missing-variable-declarations.cpp +++ b/test/SemaCXX/warn-missing-variable-declarations.cpp @@ -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 int var_template = 0; +template constexpr int const_var_template = 0; +template static int static_var_template = 0; + +template int var_template; +int use_var_template() { return var_template; } +template int var_template; +extern template int var_template; +template<> int var_template; // 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; // expected-warning {{no previous extern declaration}} -- cgit v1.2.3