Skip to content

Commit 83901cb

Browse files
committed
[libc++] Fixed copy/copy_n/copy_backward for compilers that do not support is_constant_evaluated.
Differential Revision: https://reviews.llvm.org/D69940
1 parent e9612e9 commit 83901cb

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

libcxx/include/__config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,14 @@ typedef unsigned int char32_t;
10021002
# define _LIBCPP_CONSTEXPR_AFTER_CXX17
10031003
#endif
10041004

1005+
#if _LIBCPP_STD_VER > 17 && \
1006+
!defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR) && \
1007+
!defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
1008+
# define _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED constexpr
1009+
#else
1010+
# define _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED
1011+
#endif
1012+
10051013
// The _LIBCPP_NODISCARD_ATTRIBUTE should only be used to define other
10061014
// NODISCARD macros to the correct attribute.
10071015
#if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)

libcxx/include/algorithm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ __copy(_Tp* __first, _Tp* __last, _Up* __result)
17271727
}
17281728

17291729
template <class _InputIterator, class _OutputIterator>
1730-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1730+
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED
17311731
_OutputIterator
17321732
copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
17331733
{
@@ -1780,7 +1780,7 @@ __copy_backward(_Tp* __first, _Tp* __last, _Up* __result)
17801780
}
17811781

17821782
template <class _BidirectionalIterator1, class _BidirectionalIterator2>
1783-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1783+
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED
17841784
_BidirectionalIterator2
17851785
copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
17861786
_BidirectionalIterator2 __result)
@@ -1818,7 +1818,7 @@ copy_if(_InputIterator __first, _InputIterator __last,
18181818
// copy_n
18191819

18201820
template<class _InputIterator, class _Size, class _OutputIterator>
1821-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1821+
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED
18221822
typename enable_if
18231823
<
18241824
__is_input_iterator<_InputIterator>::value &&
@@ -1844,7 +1844,7 @@ copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
18441844
}
18451845

18461846
template<class _InputIterator, class _Size, class _OutputIterator>
1847-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1847+
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED
18481848
typename enable_if
18491849
<
18501850
__is_random_access_iterator<_InputIterator>::value,

libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int main(int, char**)
7979
{
8080
test();
8181

82-
#if TEST_STD_VER > 17
82+
#if TEST_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
8383
static_assert(test());
8484
#endif
8585

libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_backward.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int main(int, char**)
5858
{
5959
test();
6060

61-
#if TEST_STD_VER > 17
61+
#if TEST_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
6262
static_assert(test());
6363
#endif
6464

libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ int main(int, char**)
8282
{
8383
test();
8484

85-
#if TEST_STD_VER > 17
85+
#if TEST_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
8686
static_assert(test());
8787
#endif
8888

0 commit comments

Comments
 (0)