Patchwork [v3] Change is_convertible to use SFINAE

login
register
mail settings
Submitter Paolo Carlini
Date July 11, 2010, 9:16 a.m.
Message ID <4C398BF7.30903@oracle.com>
Download mbox | patch
Permalink /patch/58519/
State New
Headers show

Comments

Paolo Carlini - July 11, 2010, 9:16 a.m.
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  <paolo.carlini@oracle.com>

	* 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.

Patch

Index: include/std/type_traits
===================================================================
--- include/std/type_traits	(revision 162054)
+++ include/std/type_traits	(working copy)
@@ -307,21 +307,27 @@ 
     { };
 
   template<typename _From, typename _To,
-	   bool = (is_void<_From>::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<typename _From, typename _To>
     class __is_convertible_helper<_From, _To, false>
     : public __sfinae_types
     {
-      static __one __test(_To);
-      static __two __test(...);
+      template<typename _To1>
+        static void __test_aux(_To1);
 
+      template<typename _From1, typename _To1>
+        static decltype(__test_aux<_To1>(std::declval<_From1>()), __one())
+	__test(int);
+
+      template<typename, typename>
+        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
 // <http://www.gnu.org/licenses/>.
 
-// { dg-error "static assertion failed" "" { target *-*-* } 676 }
+// { dg-error "static assertion failed" "" { target *-*-* } 682 }
 
 #include <utility>