[cfe-commits] r171088 - in /cfe/trunk: lib/Sema/Sema.cpp test/SemaCXX/warn-func-not-needed.cpp

Rafael Espindola rafael.espindola at gmail.com
Tue Dec 25 20:38:44 PST 2012


Author: rafael
Date: Tue Dec 25 22:38:44 2012
New Revision: 171088

URL: http://llvm.org/viewvc/llvm-project?rev=171088&view=rev
Log:
Fix a regression from the previous commit.
Template instantiation can set the canonical decl to used after subsequent
decls have been chained, so we have to check that too.

Modified:
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=171088&r1=171087&r2=171088&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Tue Dec 25 22:38:44 2012
@@ -328,7 +328,11 @@
 
 /// \brief Used to prune the decls of Sema's UnusedFileScopedDecls vector.
 static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) {
-  if (D->getMostRecentDecl()->isUsed())
+  // Template instantiation can happen at the end of the translation unit
+  // and it sets the canonical (first) decl to used. Normal uses set the last
+  // decl at the time to used and subsequent decl inherit the flag. The net
+  // result is that we need to check both ends of the decl chain.
+  if (D->isUsed() || D->getMostRecentDecl()->isUsed())
     return true;
 
   if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {

Modified: cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp?rev=171088&r1=171087&r2=171088&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp Tue Dec 25 22:38:44 2012
@@ -15,3 +15,16 @@
   static void g() { f(); }
   void h() { g(); }
 }
+
+namespace test3 {
+  static void f();
+  template<typename T>
+  static void g() {
+    f();
+  }
+  static void f() {
+  }
+  void h() {
+    g<int>();
+  }
+}





More information about the cfe-commits mailing list