Hello
This is my first patch submission, although I've been using clang as my
primary work compiler for over a year.
It's a simple suppression on unused function warnings
(-Wunused-function) for specialized template functions, whose primary
template has a static storage class. E.g:
---- 8< ----
template<typename T> static inline bool
isNonZero(T a) { return (bool)a; }
template<> inline bool
isNonZero(const char *s) { return s; }
---- 8< ---
Currently the second definition will emit an unused warning.
The attached patch uses the storage class from the primary template when
checking whether to omit static inline functions from the unused
warnings (since specializations implicitly inherit this storage class).
- ½
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;
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits