[PATCH] [libcxx] Correct SFINAE version of is_convertible to match spec and avoid triggering unnecessary compiler diagnostics

Agustín Bergé kaballo86 at hotmail.com
Thu Jul 10 13:13:01 PDT 2014


================
Comment at: include/type_traits:840
@@ -841,2 +839,3 @@
+template <class _Tp> typename remove_reference<_Tp>::type& __create();
 #endif
 
----------------
Couldn't `__create` be replaced by `declval`, defined earlier in this file?

================
Comment at: include/type_traits:842
@@ -842,1 +841,3 @@
 
+template <class _Tp> char helper(_Tp);
+
----------------
Shouldn't this be named `__helper` instead?

================
Comment at: include/type_traits:845
@@ +844,3 @@
+template <class _Tp, class _Tf>
+typename enable_if<sizeof(helper<_Tp>(__create<_Tf>())) == 1, char>::type
+    __test(int);
----------------
If I understand this correctly, it requires generalized SFINAE to work. Is that the intention?

================
Comment at: include/type_traits:898
@@ -892,2 +897,3 @@
+template <class _T1> struct __is_convertible<_T1, const volatile typename remove_cv<_T1>::type&&, 1, 0> : true_type {};
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
----------------
Using `add_const/volatile/cv` traits would probably be clearer here. Would that have any unwanted consequences?

http://reviews.llvm.org/D4341






More information about the cfe-commits mailing list