On 13-04-15 01:01 PM, Rafael Espíndola wrote:
Can you include a testcase in the patch?

Thanks,
Rafael
Attached is an updated patch file that includes a test case.

Thanks,

 - ½

Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp	(revision 179025)
+++ lib/Sema/SemaDecl.cpp	(working copy)
@@ -1218,8 +1218,18 @@
       if (MD->isVirtual() || IsDisallowedCopyOrAssign(MD))
         return false;
     } else {
+	FunctionDecl::StorageClass	SC;
+	
+	// If this function is a specialization, the storage class comes from the primary template.
+	// Otherwise there's no way to silence unused warnings on specializations from static 
+	// templates.
+	if (FD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+	    SC = FD->getPrimaryTemplate()->getTemplatedDecl()->getStorageClass();
+	else
+	    SC = FD->getStorageClass();
+	    
       // 'static inline' functions are used in headers; don't warn.
-      if (FD->getStorageClass() == SC_Static &&
+      if (SC == SC_Static &&
           FD->isInlineSpecified())
         return false;
     }
Index: test/SemaCXX/warn-unused-function.cpp
===================================================================
--- test/SemaCXX/warn-unused-function.cpp	(revision 0)
+++ test/SemaCXX/warn-unused-function.cpp	(revision 0)
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall %s
+
+static void f() {} // expected-warning {{unused function}}
+
+static inline void g() {}
+
+template<typename T>
+static inline bool foo(T a) { return !!a; }
+
+// This should not emit an unused-function warning since it inherits
+// the static storage type from the base template.
+template<>
+inline bool foo(int a) { return a; }
+
+
+template<typename T, typename U>
+static inline bool bar(T a, U b) { return !!a | !!b; }
+
+// Partial specialization
+template<typename U>
+inline bool bar(int a, U b) { return a || !!b; }
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to