]> granicus.if.org Git - clang/commitdiff
Fix a regression from the previous commit.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 26 Dec 2012 04:38:44 +0000 (04:38 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 26 Dec 2012 04:38:44 +0000 (04:38 +0000)
Template instantiation can set the canonical decl to used after subsequent
decls have been chained, so we have to check that too.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171088 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.cpp
test/SemaCXX/warn-func-not-needed.cpp

index e444f3c3570e6d56145c7a500530c0eb0ecd6658..4b82069a62452ab6e7f78097ddf375faa4db843b 100644 (file)
@@ -328,7 +328,11 @@ CastKind Sema::ScalarTypeToBooleanCastKind(QualType ScalarTy) {
 
 /// \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)) {
index 437a428664faa0932d8ff6ad123db395fdad5c0e..0cc639fdd201b026222a2742b72f2ceda3b52dc5 100644 (file)
@@ -15,3 +15,16 @@ namespace test2 {
   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>();
+  }
+}