diff options
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 | ||||
-rw-r--r-- | clang/test/SemaTemplate/undefined-template.cpp | 8 |
2 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 48d8b94af15..ed91057c472 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/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/clang/test/SemaTemplate/undefined-template.cpp b/clang/test/SemaTemplate/undefined-template.cpp index a03d0b7cff6..7dfe2fde94b 100644 --- a/clang/test/SemaTemplate/undefined-template.cpp +++ b/clang/test/SemaTemplate/undefined-template.cpp @@ -134,6 +134,14 @@ void func_23(C1<int>::C2<long> *x) { // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<int>::C2<long>::tmeth_2<int>' is explicitly instantiated in another translation unit}} } +namespace test_24 { + template <typename T> struct X { + friend void g(int); + operator int() { return 0; } + }; + void h(X<int> x) { g(x); } // no warning for use of 'g' despite the declaration having been instantiated from a template +} + int main() { return 0; } |