From 2faa02fc3d44e081fb7e3f36b19de622959aeb8c Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sat, 5 Oct 2013 23:29:16 +0000 Subject: [PATCH] Add tests making sure that optionals can be compared at compile time; this functionality was enabled by N3789 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@192051 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../optional.comp_with_t/equal.pass.cpp | 32 +++++++++++++------ .../optional.comp_with_t/less_than.pass.cpp | 19 ++--------- .../optional/optional.relops/equal.pass.cpp | 16 +++++++++- .../optional.relops/less_than.pass.cpp | 17 ++-------- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/test/utilities/optional/optional.comp_with_t/equal.pass.cpp b/test/utilities/optional/optional.comp_with_t/equal.pass.cpp index b1865fafe..81150ad2c 100644 --- a/test/utilities/optional/optional.comp_with_t/equal.pass.cpp +++ b/test/utilities/optional/optional.comp_with_t/equal.pass.cpp @@ -14,11 +14,25 @@ #include +#if _LIBCPP_STD_VER > 11 + +struct X +{ + int i_; + + constexpr X(int i) : i_(i) {} +}; + +constexpr bool operator == ( const X &rhs, const X &lhs ) + { return rhs.i_ == lhs.i_ ; } + +#endif + int main() { #if _LIBCPP_STD_VER > 11 { - typedef int T; + typedef X T; typedef std::optional O; constexpr T val(2); @@ -26,16 +40,16 @@ int main() constexpr O o2{1}; // engaged constexpr O o3{val}; // engaged - static_assert ( !(o1 == 1), "" ); - static_assert ( o2 == 1, "" ); - static_assert ( !(o3 == 1), "" ); - static_assert ( o3 == 2 , "" ); + static_assert ( !(o1 == T(1)), "" ); + static_assert ( o2 == T(1), "" ); + static_assert ( !(o3 == T(1)), "" ); + static_assert ( o3 == T(2) , "" ); static_assert ( o3 == val, "" ); - static_assert ( !(1 == o1), "" ); - static_assert ( 1 == o2, "" ); - static_assert ( !(1 == o3), "" ); - static_assert ( 2 == o3 , "" ); + static_assert ( !(T(1) == o1), "" ); + static_assert ( T(1) == o2, "" ); + static_assert ( !(T(1) == o3), "" ); + static_assert ( T(2) == o3 , "" ); static_assert ( val == o3 , "" ); } #endif diff --git a/test/utilities/optional/optional.comp_with_t/less_than.pass.cpp b/test/utilities/optional/optional.comp_with_t/less_than.pass.cpp index ffc4441ce..c71c8cc91 100644 --- a/test/utilities/optional/optional.comp_with_t/less_than.pass.cpp +++ b/test/utilities/optional/optional.comp_with_t/less_than.pass.cpp @@ -23,22 +23,9 @@ struct X constexpr X(int i) : i_(i) {} }; -namespace std -{ - -template <> -struct less -{ - constexpr - bool - operator()(const X& x, const X& y) const - { - return x.i_ < y.i_; - } -}; - -} - +constexpr bool operator < ( const X &rhs, const X &lhs ) + { return rhs.i_ < lhs.i_ ; } + #endif int main() diff --git a/test/utilities/optional/optional.relops/equal.pass.cpp b/test/utilities/optional/optional.relops/equal.pass.cpp index ec0503c39..a600d07ec 100644 --- a/test/utilities/optional/optional.relops/equal.pass.cpp +++ b/test/utilities/optional/optional.relops/equal.pass.cpp @@ -15,11 +15,25 @@ #include #include +#if _LIBCPP_STD_VER > 11 + +struct X +{ + int i_; + + constexpr X(int i) : i_(i) {} +}; + +constexpr bool operator == ( const X &rhs, const X &lhs ) + { return rhs.i_ == lhs.i_ ; } + +#endif + int main() { #if _LIBCPP_STD_VER > 11 { - typedef int T; + typedef X T; typedef std::optional O; constexpr O o1; // disengaged diff --git a/test/utilities/optional/optional.relops/less_than.pass.cpp b/test/utilities/optional/optional.relops/less_than.pass.cpp index a1f602148..6bcb30466 100644 --- a/test/utilities/optional/optional.relops/less_than.pass.cpp +++ b/test/utilities/optional/optional.relops/less_than.pass.cpp @@ -22,21 +22,8 @@ struct X constexpr X(int i) : i_(i) {} }; -namespace std -{ - -template <> -struct less -{ - constexpr - bool - operator()(const X& x, const X& y) const - { - return x.i_ < y.i_; - } -}; - -} +constexpr bool operator < ( const X &rhs, const X &lhs ) + { return rhs.i_ < lhs.i_ ; } #endif