From patchwork Sun Jul 11 09:16:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v3] Change is_convertible to use SFINAE Date: Sat, 10 Jul 2010 23:16:39 -0000 From: Paolo Carlini X-Patchwork-Id: 58519 Message-Id: <4C398BF7.30903@oracle.com> To: "gcc-patches@gcc.gnu.org" Cc: libstdc++ Hi, this changes is_convertible to use SFINAE, which then fails *only* because of access control (I'll add additional testcases when a couple of front-end issues are resolved). Tested x86_64-linux, committed. Paolo. //////////////////// 2010-07-11 Paolo Carlini * include/std/type_traits (is_convertible): Use SFINAE. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust dg-error line numbers. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Likewise. * testsuite/20_util/declval/requirements/1_neg.cc: Likewise. Index: include/std/type_traits =================================================================== --- include/std/type_traits (revision 162054) +++ include/std/type_traits (working copy) @@ -307,21 +307,27 @@ { }; template::value || is_void<_To>::value - || is_function<_To>::value || is_array<_To>::value)> + bool = (is_void<_From>::value || is_function<_To>::value + || is_array<_To>::value)> struct __is_convertible_helper - { static const bool __value = (is_void<_From>::value - && is_void<_To>::value); }; + { static const bool __value = is_void<_To>::value; }; template class __is_convertible_helper<_From, _To, false> : public __sfinae_types { - static __one __test(_To); - static __two __test(...); + template + static void __test_aux(_To1); + template + static decltype(__test_aux<_To1>(std::declval<_From1>()), __one()) + __test(int); + + template + static __two __test(...); + public: - static const bool __value = sizeof(__test(declval<_From>())) == 1; + static const bool __value = sizeof(__test<_From, _To>(0)) == 1; }; /// is_convertible Index: testsuite/20_util/make_signed/requirements/typedefs_neg.cc =================================================================== --- testsuite/20_util/make_signed/requirements/typedefs_neg.cc (revision 162054) +++ testsuite/20_util/make_signed/requirements/typedefs_neg.cc (working copy) @@ -48,5 +48,5 @@ // { dg-error "instantiated from here" "" { target *-*-* } 40 } // { dg-error "instantiated from here" "" { target *-*-* } 42 } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 639 } -// { dg-error "declaration of" "" { target *-*-* } 603 } +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 645 } +// { dg-error "declaration of" "" { target *-*-* } 609 } Index: testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc =================================================================== --- testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc (revision 162054) +++ testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc (working copy) @@ -48,5 +48,5 @@ // { dg-error "instantiated from here" "" { target *-*-* } 40 } // { dg-error "instantiated from here" "" { target *-*-* } 42 } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 562 } -// { dg-error "declaration of" "" { target *-*-* } 526 } +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 568 } +// { dg-error "declaration of" "" { target *-*-* } 532 } Index: testsuite/20_util/declval/requirements/1_neg.cc =================================================================== --- testsuite/20_util/declval/requirements/1_neg.cc (revision 162054) +++ testsuite/20_util/declval/requirements/1_neg.cc (working copy) @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "static assertion failed" "" { target *-*-* } 676 } +// { dg-error "static assertion failed" "" { target *-*-* } 682 } #include