diff options
author | Tom Stellard <tstellar@redhat.com> | 2018-05-31 04:15:13 +0000 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2018-05-31 04:15:13 +0000 |
commit | 742e3215bf9e9aa657d13201ccb138ab2d0090fa (patch) | |
tree | c05c6199b45cf02d41e2b3fc368efa34c2c23f75 | |
parent | fa5423e8242d4fe161c1b00fd75f49976a0c604e (diff) | |
download | llvm-742e3215bf9e9aa657d13201ccb138ab2d0090fa.zip llvm-742e3215bf9e9aa657d13201ccb138ab2d0090fa.tar.gz llvm-742e3215bf9e9aa657d13201ccb138ab2d0090fa.tar.bz2 |
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.
------------------------------------------------------------------------
llvm-svn: 333623
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 2 | ||||
-rw-r--r-- | clang/test/SemaCXX/warn-missing-variable-declarations.cpp | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 7ca48c3..0ceaf7c 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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/clang/test/SemaCXX/warn-missing-variable-declarations.cpp b/clang/test/SemaCXX/warn-missing-variable-declarations.cpp index 5b88284..5b71f38 100644 --- a/clang/test/SemaCXX/warn-missing-variable-declarations.cpp +++ b/clang/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<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}} |