From a1cd191624ac80604078b901d90c07d0122d6798 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 31 Jul 2013 21:02:34 +0000 Subject: [PATCH] Implement constexpr (n3302) and fix operator *= and /= llvm-svn: 187529 --- libcxx/include/complex | 98 +++++++++++----------- .../complex.number/cmplx.over/imag.pass.cpp | 30 +++++-- .../complex.number/cmplx.over/real.pass.cpp | 30 +++++-- .../divide_equal_complex.pass.cpp | 15 ++++ .../minus_equal_complex.pass.cpp | 14 ++++ .../complex.member.ops/plus_equal_complex.pass.cpp | 14 ++++ .../times_equal_complex.pass.cpp | 14 ++++ .../complex.members/real_imag.pass.cpp | 20 +++++ .../complex.ops/complex_equals_complex.pass.cpp | 21 ++++- .../complex.ops/complex_equals_scalar.pass.cpp | 40 +++++++-- .../complex_not_equals_complex.pass.cpp | 25 ++++-- .../complex.ops/complex_not_equals_scalar.pass.cpp | 38 +++++++-- .../complex.ops/scalar_equals_complex.pass.cpp | 36 ++++++-- .../complex.ops/scalar_not_equals_complex.pass.cpp | 38 +++++++-- 14 files changed, 329 insertions(+), 104 deletions(-) diff --git a/libcxx/include/complex b/libcxx/include/complex index a09bf70..dddc58e 100644 --- a/libcxx/include/complex +++ b/libcxx/include/complex @@ -23,12 +23,12 @@ class complex public: typedef T value_type; - complex(const T& re = T(), const T& im = T()); - complex(const complex&); - template complex(const complex&); + complex(const T& re = T(), const T& im = T()); // constexpr in C++14 + complex(const complex&); // constexpr in C++14 + template complex(const complex&); // constexpr in C++14 - T real() const; - T imag() const; + T real() const; // constexpr in C++14 + T imag() const; // constexpr in C++14 void real(T); void imag(T); @@ -149,12 +149,12 @@ template complex operator/(const complex&, const T&); template complex operator/(const T&, const complex&); template complex operator+(const complex&); template complex operator-(const complex&); -template bool operator==(const complex&, const complex&); -template bool operator==(const complex&, const T&); -template bool operator==(const T&, const complex&); -template bool operator!=(const complex&, const complex&); -template bool operator!=(const complex&, const T&); -template bool operator!=(const T&, const complex&); +template bool operator==(const complex&, const complex&); // constexpr in C++14 +template bool operator==(const complex&, const T&); // constexpr in C++14 +template bool operator==(const T&, const complex&); // constexpr in C++14 +template bool operator!=(const complex&, const complex&); // constexpr in C++14 +template bool operator!=(const complex&, const T&); // constexpr in C++14 +template bool operator!=(const T&, const complex&); // constexpr in C++14 template basic_istream& @@ -165,17 +165,17 @@ template // 26.3.7 values: -template T real(const complex&); - long double real(long double); - double real(double); -template double real(T); - float real(float); +template T real(const complex&); // constexpr in C++14 + long double real(long double); // constexpr in C++14 + double real(double); // constexpr in C++14 +template double real(T); // constexpr in C++14 + float real(float); // constexpr in C++14 -template T imag(const complex&); - long double imag(long double); - double imag(double); -template double imag(T); - float imag(float); +template T imag(const complex&); // constexpr in C++14 + long double imag(long double); // constexpr in C++14 + double imag(double); // constexpr in C++14 +template double imag(T); // constexpr in C++14 + float imag(float); // constexpr in C++14 template T abs(const complex&); @@ -269,15 +269,15 @@ private: value_type __re_; value_type __im_; public: - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 complex(const value_type& __re = value_type(), const value_type& __im = value_type()) : __re_(__re), __im_(__im) {} - template _LIBCPP_INLINE_VISIBILITY + template _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 complex(const complex<_Xp>& __c) : __re_(__c.real()), __im_(__c.imag()) {} - _LIBCPP_INLINE_VISIBILITY value_type real() const {return __re_;} - _LIBCPP_INLINE_VISIBILITY value_type imag() const {return __im_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 value_type real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 value_type imag() const {return __im_;} _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} @@ -309,12 +309,12 @@ public: } template _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) { - *this = *this * __c; + *this = *this * complex(__c.real(), __c.imag()); return *this; } template _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) { - *this = *this / __c; + *this = *this / complex(__c.real(), __c.imag()); return *this; } }; @@ -368,12 +368,12 @@ public: } template _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) { - *this = *this * __c; + *this = *this * complex(__c.real(), __c.imag()); return *this; } template _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) { - *this = *this / __c; + *this = *this / complex(__c.real(), __c.imag()); return *this; } }; @@ -424,12 +424,12 @@ public: } template _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) { - *this = *this * __c; + *this = *this * complex(__c.real(), __c.imag()); return *this; } template _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) { - *this = *this / __c; + *this = *this / complex(__c.real(), __c.imag()); return *this; } }; @@ -480,12 +480,12 @@ public: } template _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) { - *this = *this * __c; + *this = *this * complex(__c.real(), __c.imag()); return *this; } template _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) { - *this = *this / __c; + *this = *this / complex(__c.real(), __c.imag()); return *this; } }; @@ -740,7 +740,7 @@ operator-(const complex<_Tp>& __x) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator==(const complex<_Tp>& __x, const complex<_Tp>& __y) { @@ -748,7 +748,7 @@ operator==(const complex<_Tp>& __x, const complex<_Tp>& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator==(const complex<_Tp>& __x, const _Tp& __y) { @@ -756,7 +756,7 @@ operator==(const complex<_Tp>& __x, const _Tp& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator==(const _Tp& __x, const complex<_Tp>& __y) { @@ -764,7 +764,7 @@ operator==(const _Tp& __x, const complex<_Tp>& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y) { @@ -772,7 +772,7 @@ operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator!=(const complex<_Tp>& __x, const _Tp& __y) { @@ -780,7 +780,7 @@ operator!=(const complex<_Tp>& __x, const _Tp& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator!=(const _Tp& __x, const complex<_Tp>& __y) { @@ -792,21 +792,21 @@ operator!=(const _Tp& __x, const complex<_Tp>& __y) // real template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp real(const complex<_Tp>& __c) { return __c.real(); } -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 long double real(long double __re) { return __re; } -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 double real(double __re) { @@ -814,7 +814,7 @@ real(double __re) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename enable_if < is_integral<_Tp>::value, @@ -825,7 +825,7 @@ real(_Tp __re) return __re; } -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 float real(float __re) { @@ -835,21 +835,21 @@ real(float __re) // imag template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp imag(const complex<_Tp>& __c) { return __c.imag(); } -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 long double imag(long double __re) { return 0; } -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 double imag(double __re) { @@ -857,7 +857,7 @@ imag(double __re) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename enable_if < is_integral<_Tp>::value, @@ -868,7 +868,7 @@ imag(_Tp __re) return 0; } -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 float imag(float __re) { diff --git a/libcxx/test/numerics/complex.number/cmplx.over/imag.pass.cpp b/libcxx/test/numerics/complex.number/cmplx.over/imag.pass.cpp index 54fcf56..a2fe7b7 100644 --- a/libcxx/test/numerics/complex.number/cmplx.over/imag.pass.cpp +++ b/libcxx/test/numerics/complex.number/cmplx.over/imag.pass.cpp @@ -19,29 +19,41 @@ #include "../cases.h" -template +template void -test(T x, typename std::enable_if::value>::type* = 0) +test(typename std::enable_if::value>::type* = 0) { - static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); assert(std::imag(x) == 0); +#if _LIBCPP_STD_VER > 11 + constexpr T val {x}; + static_assert(std::imag(val) == 0, ""); + constexpr std::complex t{val, val}; + static_assert(t.imag() == x, "" ); +#endif } -template +template void -test(T x, typename std::enable_if::value>::type* = 0) +test(typename std::enable_if::value>::type* = 0) { - static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); assert(std::imag(x) == 0); +#if _LIBCPP_STD_VER > 11 + constexpr T val {x}; + static_assert(std::imag(val) == 0, ""); + constexpr std::complex t{val, val}; + static_assert(t.imag() == x, "" ); +#endif } template void test() { - test(0); - test(1); - test(10); + test(); + test(); + test(); } int main() diff --git a/libcxx/test/numerics/complex.number/cmplx.over/real.pass.cpp b/libcxx/test/numerics/complex.number/cmplx.over/real.pass.cpp index dcb081c..5824317 100644 --- a/libcxx/test/numerics/complex.number/cmplx.over/real.pass.cpp +++ b/libcxx/test/numerics/complex.number/cmplx.over/real.pass.cpp @@ -19,29 +19,41 @@ #include "../cases.h" -template +template void -test(T x, typename std::enable_if::value>::type* = 0) +test(typename std::enable_if::value>::type* = 0) { - static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); assert(std::real(x) == x); +#if _LIBCPP_STD_VER > 11 + constexpr T val {x}; + static_assert(std::real(val) == val, ""); + constexpr std::complex t{val, val}; + static_assert(t.real() == x, "" ); +#endif } -template +template void -test(T x, typename std::enable_if::value>::type* = 0) +test(typename std::enable_if::value>::type* = 0) { - static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); assert(std::real(x) == x); +#if _LIBCPP_STD_VER > 11 + constexpr T val {x}; + static_assert(std::real(val) == val, ""); + constexpr std::complex t{val, val}; + static_assert(t.real() == x, "" ); +#endif } template void test() { - test(0); - test(1); - test(10); + test(); + test(); + test(); } int main() diff --git a/libcxx/test/numerics/complex.number/complex.member.ops/divide_equal_complex.pass.cpp b/libcxx/test/numerics/complex.number/complex.member.ops/divide_equal_complex.pass.cpp index 1b62c5e..cb28511 100644 --- a/libcxx/test/numerics/complex.number/complex.member.ops/divide_equal_complex.pass.cpp +++ b/libcxx/test/numerics/complex.number/complex.member.ops/divide_equal_complex.pass.cpp @@ -28,6 +28,21 @@ test() c /= c2; assert(c.real() == 1); assert(c.imag() == 0); + + std::complex c3; + + c3 = c; + std::complex ic (1,1); + c3 /= ic; + assert(c3.real() == 0.5); + assert(c3.imag() == -0.5); + + c3 = c; + std::complex fc (1,1); + c3 /= fc; + assert(c3.real() == 0.5); + assert(c3.imag() == -0.5); + } int main() diff --git a/libcxx/test/numerics/complex.number/complex.member.ops/minus_equal_complex.pass.cpp b/libcxx/test/numerics/complex.number/complex.member.ops/minus_equal_complex.pass.cpp index ed57ee8..67a1c71 100644 --- a/libcxx/test/numerics/complex.number/complex.member.ops/minus_equal_complex.pass.cpp +++ b/libcxx/test/numerics/complex.number/complex.member.ops/minus_equal_complex.pass.cpp @@ -28,6 +28,20 @@ test() c -= c2; assert(c.real() == -3); assert(c.imag() == -5); + + std::complex c3; + + c3 = c; + std::complex ic (1,1); + c3 -= ic; + assert(c3.real() == -4); + assert(c3.imag() == -6); + + c3 = c; + std::complex fc (1,1); + c3 -= fc; + assert(c3.real() == -4); + assert(c3.imag() == -6); } int main() diff --git a/libcxx/test/numerics/complex.number/complex.member.ops/plus_equal_complex.pass.cpp b/libcxx/test/numerics/complex.number/complex.member.ops/plus_equal_complex.pass.cpp index b37e812..8c16f4c 100644 --- a/libcxx/test/numerics/complex.number/complex.member.ops/plus_equal_complex.pass.cpp +++ b/libcxx/test/numerics/complex.number/complex.member.ops/plus_equal_complex.pass.cpp @@ -28,6 +28,20 @@ test() c += c2; assert(c.real() == 3); assert(c.imag() == 5); + + std::complex c3; + + c3 = c; + std::complex ic (1,1); + c3 += ic; + assert(c3.real() == 4); + assert(c3.imag() == 6); + + c3 = c; + std::complex fc (1,1); + c3 += fc; + assert(c3.real() == 4); + assert(c3.imag() == 6); } int main() diff --git a/libcxx/test/numerics/complex.number/complex.member.ops/times_equal_complex.pass.cpp b/libcxx/test/numerics/complex.number/complex.member.ops/times_equal_complex.pass.cpp index 72825d9..84d6e59 100644 --- a/libcxx/test/numerics/complex.number/complex.member.ops/times_equal_complex.pass.cpp +++ b/libcxx/test/numerics/complex.number/complex.member.ops/times_equal_complex.pass.cpp @@ -28,6 +28,20 @@ test() c *= c2; assert(c.real() == -4); assert(c.imag() == 7.5); + + std::complex c3; + + c3 = c; + std::complex ic (1,1); + c3 *= ic; + assert(c3.real() == -11.5); + assert(c3.imag() == 3.5); + + c3 = c; + std::complex fc (1,1); + c3 *= fc; + assert(c3.real() == -11.5); + assert(c3.imag() == 3.5); } int main() diff --git a/libcxx/test/numerics/complex.number/complex.members/real_imag.pass.cpp b/libcxx/test/numerics/complex.number/complex.members/real_imag.pass.cpp index 043cdd2..7ead855 100644 --- a/libcxx/test/numerics/complex.number/complex.members/real_imag.pass.cpp +++ b/libcxx/test/numerics/complex.number/complex.members/real_imag.pass.cpp @@ -17,6 +17,23 @@ template void +test_constexpr() +{ +#if _LIBCPP_STD_VER > 11 + constexpr std::complex c1; + static_assert(c1.real() == 0, ""); + static_assert(c1.imag() == 0, ""); + constexpr std::complex c2(3); + static_assert(c2.real() == 3, ""); + static_assert(c2.imag() == 0, ""); + constexpr std::complex c3(3, 4); + static_assert(c3.real() == 3, ""); + static_assert(c3.imag() == 4, ""); +#endif +} + +template +void test() { std::complex c; @@ -34,6 +51,8 @@ test() c.imag(-5.5); assert(c.real() == -4.5); assert(c.imag() == -5.5); + + test_constexpr (); } int main() @@ -41,4 +60,5 @@ int main() test(); test(); test(); + test_constexpr (); } diff --git a/libcxx/test/numerics/complex.number/complex.ops/complex_equals_complex.pass.cpp b/libcxx/test/numerics/complex.number/complex.ops/complex_equals_complex.pass.cpp index 2af2150..970f021 100644 --- a/libcxx/test/numerics/complex.number/complex.ops/complex_equals_complex.pass.cpp +++ b/libcxx/test/numerics/complex.number/complex.ops/complex_equals_complex.pass.cpp @@ -18,9 +18,20 @@ template void -test(const std::complex& lhs, const std::complex& rhs, bool x) +test_constexpr() { - assert((lhs == rhs) == x); +#if _LIBCPP_STD_VER > 11 + { + constexpr std::complex lhs(1.5, 2.5); + constexpr std::complex rhs(1.5, -2.5); + static_assert( !(lhs == rhs), ""); + } + { + constexpr std::complex lhs(1.5, 2.5); + constexpr std::complex rhs(1.5, 2.5); + static_assert(lhs == rhs, ""); + } +#endif } template @@ -30,13 +41,14 @@ test() { std::complex lhs(1.5, 2.5); std::complex rhs(1.5, -2.5); - test(lhs, rhs, false); + assert( !(lhs == rhs)); } { std::complex lhs(1.5, 2.5); std::complex rhs(1.5, 2.5); - test(lhs, rhs, true); + assert(lhs == rhs); } + test_constexpr (); } int main() @@ -44,4 +56,5 @@ int main() test(); test(); test(); +// test_constexpr (); } diff --git a/libcxx/test/numerics/complex.number/complex.ops/complex_equals_scalar.pass.cpp b/libcxx/test/numerics/complex.number/complex.ops/complex_equals_scalar.pass.cpp index 4b6edac..3c8b772 100644 --- a/libcxx/test/numerics/complex.number/complex.ops/complex_equals_scalar.pass.cpp +++ b/libcxx/test/numerics/complex.number/complex.ops/complex_equals_scalar.pass.cpp @@ -18,9 +18,30 @@ template void -test(const std::complex& lhs, const T& rhs, bool x) +test_constexpr() { - assert((lhs == rhs) == x); +#if _LIBCPP_STD_VER > 11 + { + constexpr std::complex lhs(1.5, 2.5); + constexpr T rhs(-2.5); + static_assert(!(lhs == rhs), ""); + } + { + constexpr std::complex lhs(1.5, 0); + constexpr T rhs(-2.5); + static_assert(!(lhs == rhs), ""); + } + { + constexpr std::complex lhs(1.5, 2.5); + constexpr T rhs(1.5); + static_assert(!(lhs == rhs), ""); + } + { + constexpr std::complex lhs(1.5, 0); + constexpr T rhs(1.5); + static_assert( (lhs == rhs), ""); + } +#endif } template @@ -30,28 +51,31 @@ test() { std::complex lhs(1.5, 2.5); T rhs(-2.5); - test(lhs, rhs, false); + assert(!(lhs == rhs)); } { - std::complex lhs(1.5, 0); + std::complex lhs(1.5, 0); T rhs(-2.5); - test(lhs, rhs, false); + assert(!(lhs == rhs)); } { std::complex lhs(1.5, 2.5); T rhs(1.5); - test(lhs, rhs, false); + assert(!(lhs == rhs)); } { std::complex lhs(1.5, 0); T rhs(1.5); - test(lhs, rhs, true); + assert( (lhs == rhs)); + } + + test_constexpr (); } -} int main() { test(); test(); test(); +// test_constexpr (); } diff --git a/libcxx/test/numerics/complex.number/complex.ops/complex_not_equals_complex.pass.cpp b/libcxx/test/numerics/complex.number/complex.ops/complex_not_equals_complex.pass.cpp index 9f40a18..f5ff3fd 100644 --- a/libcxx/test/numerics/complex.number/complex.ops/complex_not_equals_complex.pass.cpp +++ b/libcxx/test/numerics/complex.number/complex.ops/complex_not_equals_complex.pass.cpp @@ -18,11 +18,23 @@ template void -test(const std::complex& lhs, const std::complex& rhs, bool x) +test_constexpr() { - assert((lhs != rhs) == x); +#if _LIBCPP_STD_VER > 11 + { + constexpr std::complex lhs(1.5, 2.5); + constexpr std::complex rhs(1.5, -2.5); + static_assert(lhs != rhs, ""); + } + { + constexpr std::complex lhs(1.5, 2.5); + constexpr std::complex rhs(1.5, 2.5); + static_assert(!(lhs != rhs), "" ); + } +#endif } + template void test() @@ -30,18 +42,21 @@ test() { std::complex lhs(1.5, 2.5); std::complex rhs(1.5, -2.5); - test(lhs, rhs, true); + assert(lhs != rhs); } { std::complex lhs(1.5, 2.5); std::complex rhs(1.5, 2.5); - test(lhs, rhs, false); + assert(!(lhs != rhs)); } -} + + test_constexpr (); + } int main() { test(); test(); test(); +// test_constexpr (); } diff --git a/libcxx/test/numerics/complex.number/complex.ops/complex_not_equals_scalar.pass.cpp b/libcxx/test/numerics/complex.number/complex.ops/complex_not_equals_scalar.pass.cpp index b43c095..efb1c0e 100644 --- a/libcxx/test/numerics/complex.number/complex.ops/complex_not_equals_scalar.pass.cpp +++ b/libcxx/test/numerics/complex.number/complex.ops/complex_not_equals_scalar.pass.cpp @@ -18,9 +18,30 @@ template void -test(const std::complex& lhs, const T& rhs, bool x) +test_constexpr() { - assert((lhs != rhs) == x); +#if _LIBCPP_STD_VER > 11 + { + constexpr std::complex lhs(1.5, 2.5); + constexpr T rhs(-2.5); + static_assert(lhs != rhs, ""); + } + { + constexpr std::complex lhs(1.5, 0); + constexpr T rhs(-2.5); + static_assert(lhs != rhs, ""); + } + { + constexpr std::complex lhs(1.5, 2.5); + constexpr T rhs(1.5); + static_assert(lhs != rhs, ""); + } + { + constexpr std::complex lhs(1.5, 0); + constexpr T rhs(1.5); + static_assert( !(lhs != rhs), ""); + } +#endif } template @@ -30,23 +51,25 @@ test() { std::complex lhs(1.5, 2.5); T rhs(-2.5); - test(lhs, rhs, true); + assert(lhs != rhs); } { std::complex lhs(1.5, 0); T rhs(-2.5); - test(lhs, rhs, true); + assert(lhs != rhs); } { std::complex lhs(1.5, 2.5); T rhs(1.5); - test(lhs, rhs, true); + assert(lhs != rhs); } { std::complex lhs(1.5, 0); T rhs(1.5); - test(lhs, rhs, false); + assert( !(lhs != rhs)); } + + test_constexpr (); } int main() @@ -54,4 +77,5 @@ int main() test(); test(); test(); -} +// test_constexpr (); + } diff --git a/libcxx/test/numerics/complex.number/complex.ops/scalar_equals_complex.pass.cpp b/libcxx/test/numerics/complex.number/complex.ops/scalar_equals_complex.pass.cpp index d4fdc14..0cd9035 100644 --- a/libcxx/test/numerics/complex.number/complex.ops/scalar_equals_complex.pass.cpp +++ b/libcxx/test/numerics/complex.number/complex.ops/scalar_equals_complex.pass.cpp @@ -18,9 +18,30 @@ template void -test(const T& lhs, const std::complex& rhs, bool x) +test_constexpr() { - assert((lhs == rhs) == x); +#if _LIBCPP_STD_VER > 11 + { + constexpr T lhs(-2.5); + constexpr std::complex rhs(1.5, 2.5); + static_assert(!(lhs == rhs), ""); + } + { + constexpr T lhs(-2.5); + constexpr std::complex rhs(1.5, 0); + static_assert(!(lhs == rhs), ""); + } + { + constexpr T lhs(1.5); + constexpr std::complex rhs(1.5, 2.5); + static_assert(!(lhs == rhs), ""); + } + { + constexpr T lhs(1.5); + constexpr std::complex rhs(1.5, 0); + static_assert(lhs == rhs, ""); + } +#endif } template @@ -30,23 +51,25 @@ test() { T lhs(-2.5); std::complex rhs(1.5, 2.5); - test(lhs, rhs, false); + assert(!(lhs == rhs)); } { T lhs(-2.5); std::complex rhs(1.5, 0); - test(lhs, rhs, false); + assert(!(lhs == rhs)); } { T lhs(1.5); std::complex rhs(1.5, 2.5); - test(lhs, rhs, false); + assert(!(lhs == rhs)); } { T lhs(1.5); std::complex rhs(1.5, 0); - test(lhs, rhs, true); + assert(lhs == rhs); } + + test_constexpr (); } int main() @@ -54,4 +77,5 @@ int main() test(); test(); test(); +// test_constexpr(); } diff --git a/libcxx/test/numerics/complex.number/complex.ops/scalar_not_equals_complex.pass.cpp b/libcxx/test/numerics/complex.number/complex.ops/scalar_not_equals_complex.pass.cpp index 877ddb3..7d6003c 100644 --- a/libcxx/test/numerics/complex.number/complex.ops/scalar_not_equals_complex.pass.cpp +++ b/libcxx/test/numerics/complex.number/complex.ops/scalar_not_equals_complex.pass.cpp @@ -18,9 +18,30 @@ template void -test(const T& lhs, const std::complex& rhs, bool x) +test_constexpr() { - assert((lhs != rhs) == x); +#if _LIBCPP_STD_VER > 11 + { + constexpr T lhs(-2.5); + constexpr std::complex rhs(1.5, 2.5); + static_assert (lhs != rhs, ""); + } + { + constexpr T lhs(-2.5); + constexpr std::complex rhs(1.5, 0); + static_assert (lhs != rhs, ""); + } + { + constexpr T lhs(1.5); + constexpr std::complex rhs(1.5, 2.5); + static_assert (lhs != rhs, ""); + } + { + constexpr T lhs(1.5); + constexpr std::complex rhs(1.5, 0); + static_assert (!(lhs != rhs), ""); + } +#endif } template @@ -30,28 +51,31 @@ test() { T lhs(-2.5); std::complex rhs(1.5, 2.5); - test(lhs, rhs, true); + assert (lhs != rhs); } { T lhs(-2.5); std::complex rhs(1.5, 0); - test(lhs, rhs, true); + assert (lhs != rhs); } { T lhs(1.5); std::complex rhs(1.5, 2.5); - test(lhs, rhs, true); + assert (lhs != rhs); } { T lhs(1.5); std::complex rhs(1.5, 0); - test(lhs, rhs, false); + assert (!(lhs != rhs)); + } + + test_constexpr (); } -} int main() { test(); test(); test(); +// test_constexpr(); } -- 2.7.4