[PATCH] D29877: Warn about unused static file scope function template declarations.
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Tue May 9 06:29:21 PDT 2017
On 11/04/17 22:25, Richard Smith wrote:
> On 11 April 2017 at 08:35, Marshall Clow via Phabricator via
> cfe-commits <cfe-commits at lists.llvm.org
> <mailto:cfe-commits at lists.llvm.org>> wrote:
>
> mclow.lists added a comment.
>
> Complete reproducer:
>
> // Tested with with: clang++ -std=c++14 -Wunused-function
> UnusedFVassily.cpp
> //
> // UnusedFVassily.cpp:8:39: warning: unused function '__test'
> [-Wunused-function]
> // template <class _Up> static __two __test(...);
> // ^
> // UnusedFVassily.cpp:9:38: warning: unused function '__test'
> [-Wunused-function]
> // template <class _Up> static char __test(typename
> _Up::pointer* = 0);
> // ^
> // 2 warnings generated.
>
> #include <type_traits>
>
> namespace foo {
>
> struct __two {char __lx; char __lxx;};
> namespace __has_pointer_type_imp
> {
>
> template <class _Up> static __two __test(...);
> template <class _Up> static char __test(typename _Up::pointer* = 0);
>
> }
>
> template <class _Tp>
> struct __has_pointer_type
>
> : public std::integral_constant<bool,
> sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
>
>
> This is a bug in libc++. If this header is included into two
> translation units, they will be referencing different __test functions
> here (because the template has internal linkage due to the 'static'),
> resulting in an ODR violation.
Richard, shall we warn on template definitions marked static? This would
keep this pattern still working.
>
>
> {
> };
>
> }
>
> struct S1 {};
> struct S2 { typedef void *pointer; };
>
> int main () {
> static_assert (!foo::__has_pointer_type<S1>::value, "" );
> static_assert ( foo::__has_pointer_type<S2>::value, "" );
> }
>
>
> https://reviews.llvm.org/D29877 <https://reviews.llvm.org/D29877>
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org <mailto:cfe-commits at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170509/6229c1ee/attachment-0001.html>
More information about the cfe-commits
mailing list