From b5ee3be0f17a28cbcd1d5f5ff5cc6b336bce65de Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 28 Jan 2017 01:50:33 +0000 Subject: [PATCH] -Wunused-func-template: do not warn on non-template function declarations that were nonetheless instantiated (particularly, non-template friends declared within class templates). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293358 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 ++++++- test/SemaTemplate/undefined-template.cpp | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 48d8b94af1..ed91057c47 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3726,7 +3726,12 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, PendingInstantiations.push_back( std::make_pair(Function, PointOfInstantiation)); } else if (TSK == TSK_ImplicitInstantiation) { - if (AtEndOfTU && !getDiagnostics().hasErrorOccurred()) { + if (AtEndOfTU && !getDiagnostics().hasErrorOccurred() && + // A non-template function that is only lexically in a dependent + // context, such as a friend function in a class template, should + // not produce a warning. + (PatternDecl->getDescribedFunctionTemplate() || + PatternDecl->getDeclContext()->isDependentContext())) { Diag(PointOfInstantiation, diag::warn_func_template_missing) << Function; Diag(PatternDecl->getLocation(), diag::note_forward_template_decl); diff --git a/test/SemaTemplate/undefined-template.cpp b/test/SemaTemplate/undefined-template.cpp index a03d0b7cff..7dfe2fde94 100644 --- a/test/SemaTemplate/undefined-template.cpp +++ b/test/SemaTemplate/undefined-template.cpp @@ -134,6 +134,14 @@ void func_23(C1::C2 *x) { // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1::C2::tmeth_2' is explicitly instantiated in another translation unit}} } +namespace test_24 { + template struct X { + friend void g(int); + operator int() { return 0; } + }; + void h(X x) { g(x); } // no warning for use of 'g' despite the declaration having been instantiated from a template +} + int main() { return 0; } -- 2.40.0