]> granicus.if.org Git - clang/commitdiff
Remove all "used" static functions *after* we have performed all of
authorDouglas Gregor <dgregor@apple.com>
Fri, 9 Apr 2010 17:41:13 +0000 (17:41 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 9 Apr 2010 17:41:13 +0000 (17:41 +0000)
the implicit template instantiations we need to perform. Otherwise, we
end up erroneously diagnosing static functions as used if they were
only used within an implicit template instantiation. Fixes a bunch of
spurious failures when building Clang with Clang.

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

lib/Sema/Sema.cpp
test/SemaCXX/unused-functions.cpp [new file with mode: 0644]

index ccfbe1e00a7eb6d765d0f4f5719e0bc8dbf2e7f2..2bb1ed8ce914637e38ed194232ba3809102ce0ef 100644 (file)
@@ -197,14 +197,7 @@ void Sema::DeleteStmt(StmtTy *S) {
 /// ActOnEndOfTranslationUnit - This is called at the very end of the
 /// translation unit when EOF is reached and all but the top-level scope is
 /// popped.
-void Sema::ActOnEndOfTranslationUnit() {
-  
-  // Remove functions that turned out to be used.
-  UnusedStaticFuncs.erase(std::remove_if(UnusedStaticFuncs.begin(), 
-                                         UnusedStaticFuncs.end(), 
-                                         std::mem_fun(&FunctionDecl::isUsed)), 
-                          UnusedStaticFuncs.end());
-  
+void Sema::ActOnEndOfTranslationUnit() {  
   while (1) {
     // C++: Perform implicit template instantiations.
     //
@@ -225,6 +218,12 @@ void Sema::ActOnEndOfTranslationUnit() {
       break;
   }
   
+  // Remove functions that turned out to be used.
+  UnusedStaticFuncs.erase(std::remove_if(UnusedStaticFuncs.begin(), 
+                                         UnusedStaticFuncs.end(), 
+                                         std::mem_fun(&FunctionDecl::isUsed)), 
+                          UnusedStaticFuncs.end());
+
   // Check for #pragma weak identifiers that were never declared
   // FIXME: This will cause diagnostics to be emitted in a non-determinstic
   // order!  Iterating over a densemap like this is bad.
diff --git a/test/SemaCXX/unused-functions.cpp b/test/SemaCXX/unused-functions.cpp
new file mode 100644 (file)
index 0000000..cefa9e1
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused -verify %s
+
+static int foo(int x) { return x; }
+
+template<typename T>
+T get_from_foo(T y) { return foo(y); }
+
+int g(int z) { return get_from_foo(z); }