From: Vassil Vassilev Date: Tue, 11 Apr 2017 16:05:23 +0000 (+0000) Subject: Revert temporarily D29877 "Warn about unused static file scope function template... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9f266a5e168a9461371331a8b41b85a0b7484a2a;p=clang Revert temporarily D29877 "Warn about unused static file scope function template declarations." We need to address cases (breaking libc++) such as template static int __test(...); template auto v = __test<_Tp>(0); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299956 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index f943ab5650..294b56059b 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -470,13 +470,6 @@ static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) { return true; if (const FunctionDecl *FD = dyn_cast(D)) { - // If this is a function template and none of its specializations is used, - // we should warn. - if (FunctionTemplateDecl *Template = FD->getDescribedFunctionTemplate()) - for (const auto *Spec : Template->specializations()) - if (ShouldRemoveFromUnused(SemaRef, Spec)) - return true; - // UnusedFileScopedDecls stores the first declaration. // The declaration may have become definition so check again. const FunctionDecl *DeclToCheck; @@ -500,13 +493,6 @@ static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) { VD->isUsableInConstantExpressions(SemaRef->Context)) return true; - if (VarTemplateDecl *Template = VD->getDescribedVarTemplate()) - // If this is a variable template and none of its specializations is used, - // we should warn. - for (const auto *Spec : Template->specializations()) - if (ShouldRemoveFromUnused(SemaRef, Spec)) - return true; - // UnusedFileScopedDecls stores the first declaration. // The declaration may have become definition so check again. const VarDecl *DeclToCheck = VD->getDefinition(); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 20d1e0c6da..02cbca8b2b 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -8887,7 +8887,6 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, if (FunctionTemplate) { if (NewFD->isInvalidDecl()) FunctionTemplate->setInvalidDecl(); - MarkUnusedFileScopedDecl(NewFD); return FunctionTemplate; } } @@ -10988,7 +10987,8 @@ static bool hasDependentAlignment(VarDecl *VD) { /// FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform /// any semantic actions necessary after any initializer has been attached. -void Sema::FinalizeDeclaration(Decl *ThisDecl) { +void +Sema::FinalizeDeclaration(Decl *ThisDecl) { // Note that we are no longer parsing the initializer for this declaration. ParsingInitForAutoVars.erase(ThisDecl); @@ -11153,8 +11153,9 @@ void Sema::FinalizeDeclaration(Decl *ThisDecl) { if (DC->getRedeclContext()->isFileContext() && VD->isExternallyVisible()) AddPushedVisibilityAttribute(VD); - // FIXME: Warn on unused var template partial specializations. - if (VD->isFileVarDecl() && !isa(VD)) + // FIXME: Warn on unused templates. + if (VD->isFileVarDecl() && !VD->getDescribedVarTemplate() && + !isa(VD)) MarkUnusedFileScopedDecl(VD); // Now we have parsed the initializer and can update the table of magic diff --git a/test/SemaCXX/warn-unused-filescoped.cpp b/test/SemaCXX/warn-unused-filescoped.cpp index bd9335d321..18defee7d0 100644 --- a/test/SemaCXX/warn-unused-filescoped.cpp +++ b/test/SemaCXX/warn-unused-filescoped.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -Wno-c++11-extensions -std=c++98 %s -// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -std=c++14 %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -std=c++11 %s #ifdef HEADER @@ -65,7 +65,7 @@ namespace { template <> void TS::m() { } // expected-warning{{unused}} template - void tf() { } // expected-warning{{unused}} + void tf() { } template <> void tf() { } // expected-warning{{unused}} struct VS { @@ -200,18 +200,6 @@ void bar() { void func() __attribute__((used)); } static void func() {} } -namespace test9 { -template -static void completeRedeclChainForTemplateSpecialization() { } // expected-warning {{unused}} -} - -namespace test10 { -#if __cplusplus >= 201103L -template -constexpr T pi = T(3.14); // expected-warning {{unused}} -#endif -} - namespace pr19713 { #if __cplusplus >= 201103L // FIXME: We should warn on both of these.