Author: chandlerc
Date: Mon Jan  3 13:27:19 2011
New Revision: 122763

URL: http://llvm.org/viewvc/llvm-project?rev=122763&view=rev
Log:
Fix PR8841 by checking for  both semantic and lecical dependent
contexts. This prevents -Wunused-function from firing on friend function
definitions inside of class templates for example.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=122763&r1=122762&r2=122763&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan  3 13:27:19 2011
@@ -557,7 +557,8 @@
     return false;
 
   // Ignore class templates.
-  if (D->getDeclContext()->isDependentContext())
+  if (D->getDeclContext()->isDependentContext() ||
+      D->getLexicalDeclContext()->isDependentContext())
     return false;
 
   if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {

Modified: cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp?rev=122763&r1=122762&r2=122763&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp Mon Jan  3 13:27:19 2011
@@ -54,3 +54,19 @@
   };
   template <> int TS2<int>::x;  // expected-warning{{unused}}
 }
+
+namespace PR8841 {
+  // Ensure that friends of class templates are considered to have a dependent
+  // context and not marked unused.
+  namespace {
+    template <typename T> struct X {
+      friend bool operator==(const X&, const X&) { return false; }
+    };
+  }
+  template <typename T> void template_test(X<T> x) {
+    (void)(x == x);
+  }
+  void test(X<int> x) {
+    template_test(x);
+  }
+}


_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to