[libc++] Fixed copy/copy_n/copy_backward for compilers that do not support is_constan...
authorLouis Dionne <ldionne@apple.com>
Thu, 7 Nov 2019 12:30:32 +0000 (12:30 +0000)
committerLouis Dionne <ldionne@apple.com>
Thu, 7 Nov 2019 12:39:10 +0000 (12:39 +0000)
Differential Revision: https://reviews.llvm.org/D69940

libcxx/include/__config
libcxx/include/algorithm
libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp
libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_backward.pass.cpp
libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp

index 044cd0ceb0073fef969e2dd22b2216d273e07e3d..47b40c49cf79102ebf9a04975668c746cd6cc26c 100644 (file)
@@ -1002,6 +1002,14 @@ typedef unsigned int   char32_t;
 #  define _LIBCPP_CONSTEXPR_AFTER_CXX17
 #endif
 
+#if _LIBCPP_STD_VER > 17 && \
+    !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR) && \
+    !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
+#  define _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED constexpr
+#else
+#  define _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED
+#endif
+
 // The _LIBCPP_NODISCARD_ATTRIBUTE should only be used to define other
 // NODISCARD macros to the correct attribute.
 #if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)
index 419ec2ce577636059f0a7f789f323638e92c7ceb..7481cc21ca539787407a7ad3c0ff5d4d28e4a830 100644 (file)
@@ -1727,7 +1727,7 @@ __copy(_Tp* __first, _Tp* __last, _Up* __result)
 }
 
 template <class _InputIterator, class _OutputIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED
 _OutputIterator
 copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
 {
@@ -1780,7 +1780,7 @@ __copy_backward(_Tp* __first, _Tp* __last, _Up* __result)
 }
 
 template <class _BidirectionalIterator1, class _BidirectionalIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED
 _BidirectionalIterator2
 copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
               _BidirectionalIterator2 __result)
@@ -1818,7 +1818,7 @@ copy_if(_InputIterator __first, _InputIterator __last,
 // copy_n
 
 template<class _InputIterator, class _Size, class _OutputIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED
 typename enable_if
 <
     __is_input_iterator<_InputIterator>::value &&
@@ -1844,7 +1844,7 @@ copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
 }
 
 template<class _InputIterator, class _Size, class _OutputIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED
 typename enable_if
 <
     __is_random_access_iterator<_InputIterator>::value,
index 2cdd3b9799c12ab6705fa0a5f232596dd468efbb..ab6aaa241b1e973996464cd88695c849ce388bc2 100644 (file)
@@ -79,7 +79,7 @@ int main(int, char**)
 {
     test();
 
-#if TEST_STD_VER > 17
+#if TEST_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
     static_assert(test());
 #endif
 
index 6eb403d525dc19f7516acf334017639cdff38ca9..11eb21f202d350460f854a7a76170cd8acf0f5dc 100644 (file)
@@ -58,7 +58,7 @@ int main(int, char**)
 {
     test();
 
-#if TEST_STD_VER > 17
+#if TEST_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
     static_assert(test());
 #endif
 
index 72c22b53b549b3cf2c6f3c48e6c3e8c6a1b5f403..8c4900fe33b4104e1ab082e6d79f89696ac5756e 100644 (file)
@@ -82,7 +82,7 @@ int main(int, char**)
 {
     test();
 
-#if TEST_STD_VER > 17
+#if TEST_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
     static_assert(test());
 #endif