]> granicus.if.org Git - clang/commitdiff
-Wunused-func-template: do not warn on non-template function declarations that
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 28 Jan 2017 01:50:33 +0000 (01:50 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 28 Jan 2017 01:50:33 +0000 (01:50 +0000)
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
test/SemaTemplate/undefined-template.cpp

index 48d8b94af1539e96e17830f5346af80ed9bfb3c9..ed91057c4721dd3337f130ccb5144461869e3125 100644 (file)
@@ -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);
index a03d0b7cff6266145241b46d806dadd3afcfa33e..7dfe2fde94b0a64d013ce71f7300c5ce9180180e 100644 (file)
@@ -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;
 }