r179598 - Suppress unused warning on static inline function template specializations.

Rafael Espindola rafael.espindola at gmail.com
Tue Apr 16 08:21:30 PDT 2013


Author: rafael
Date: Tue Apr 16 10:21:30 2013
New Revision: 179598

URL: http://llvm.org/viewvc/llvm-project?rev=179598&view=rev
Log:
Suppress unused warning on static inline function template specializations.

Patch by Halfdan Ingvarsson!

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=179598&r1=179597&r2=179598&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Apr 16 10:21:30 2013
@@ -1219,7 +1219,10 @@ bool Sema::ShouldWarnIfUnusedFileScopedD
         return false;
     } else {
       // 'static inline' functions are used in headers; don't warn.
-      if (FD->getStorageClass() == SC_Static &&
+      // Make sure we get the storage class from the canonical declaration,
+      // since otherwise we will get spurious warnings on specialized
+      // static template functions.
+      if (FD->getCanonicalDecl()->getStorageClass() == SC_Static &&
           FD->isInlineSpecified())
         return false;
     }

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=179598&r1=179597&r2=179598&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp Tue Apr 16 10:21:30 2013
@@ -133,6 +133,27 @@ namespace test6 {
   };
 }
 
+namespace test7
+{
+  template<typename T>
+  static inline void foo(T) { }
+
+  // This should not emit an unused-function warning since it inherits
+  // the static storage type from the base template.
+  template<>
+  inline void foo(int) {  }
+
+  // Partial specialization
+  template<typename T, typename U>
+  static inline void bar(T, U) { }
+
+  template<typename U>
+  inline void bar(int, U) { }
+
+  template<>
+  inline void bar(int, int) { }
+};
+
 namespace pr14776 {
   namespace {
     struct X {};





More information about the cfe-commits mailing list