Compare commits

...

4 Commits

Author SHA1 Message Date
Andrey Semashev
f3963f5375 Attempt to work around C++20 operator rewriting causinginfinite recursion.
Fixes https://github.com/boostorg/utility/issues/65.
2020-11-30 01:52:44 +03:00
Peter Dimov
37168a3f4b Use address-model=32 for msvc-9.0, 10.0, 11.0 2020-10-12 00:01:10 +03:00
Glen Fernandes
e56171989a Merge pull request #69 from giomasce-throwaway/develop
Fix copyright headers.
2020-10-11 11:48:14 -04:00
Giovanni Mascellani
f00a5bf0d3 Fix copyright headers. 2020-10-11 17:35:14 +02:00
5 changed files with 50 additions and 5 deletions

View File

@@ -15,9 +15,10 @@ branches:
environment:
matrix:
- TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0,msvc-12.0
- TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0
ADDRMD: 32
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
- TOOLSET: msvc-14.0
- TOOLSET: msvc-12.0,msvc-14.0
ADDRMD: 32,64
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
- TOOLSET: msvc-14.1

View File

@@ -1,6 +1,6 @@
[/
/ Copyright (c) 2008 Howard Hinnant
/ Copyright (c) 2009-20012 Vicente J. Botet Escriba
/ Copyright (c) 2009-2012 Vicente J. Botet Escriba
/
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -100,6 +100,11 @@
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/core/addressof.hpp>
#if defined(__cpp_impl_three_way_comparison)
#include <boost/core/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/declval.hpp>
#endif
#if defined(__sgi) && !defined(__GNUC__)
# pragma set woff 1234
@@ -158,9 +163,21 @@ struct less_than_comparable1 : B
template <class T, class U, class B = operators_detail::empty_base<T> >
struct equality_comparable2 : B
{
#if defined(__cpp_impl_three_way_comparison)
template< typename R = decltype(boost::declval< T const& >() == boost::declval< U const& >()) >
friend BOOST_OPERATORS_CONSTEXPR
typename boost::enable_if_c< !boost::is_same< R, bool >::value, bool >::type
operator==(const U& y, const T& x) { return x == y; }
template< typename R = decltype(boost::declval< T const& >() == boost::declval< U const& >()) >
friend BOOST_OPERATORS_CONSTEXPR
typename boost::enable_if_c< !boost::is_same< R, bool >::value, bool >::type
operator!=(const U& y, const T& x) { return !static_cast<bool>(x == y); }
#else
friend BOOST_OPERATORS_CONSTEXPR bool operator==(const U& y, const T& x) { return x == y; }
friend BOOST_OPERATORS_CONSTEXPR bool operator!=(const U& y, const T& x) { return !static_cast<bool>(x == y); }
friend BOOST_OPERATORS_CONSTEXPR bool operator!=(const T& y, const U& x) { return !static_cast<bool>(y == x); }
#endif
friend BOOST_OPERATORS_CONSTEXPR bool operator!=(const T& x, const U& y) { return !static_cast<bool>(x == y); }
};
template <class T, class B = operators_detail::empty_base<T> >

View File

@@ -144,9 +144,11 @@ struct less_than_comparable1 : B
template <class T, class U, class B = ::boost::detail::empty_base<T> >
struct equality_comparable2 : B
{
#if !defined(__cpp_impl_three_way_comparison)
friend bool operator==(const U& y, const T& x) { return x == y; }
friend bool operator!=(const U& y, const T& x) { return !static_cast<bool>(x == y); }
friend bool operator!=(const T& y, const U& x) { return !static_cast<bool>(y == x); }
#endif
friend bool operator!=(const T& x, const U& y) { return !static_cast<bool>(x == y); }
};
template <class T, class B = ::boost::detail::empty_base<T> >

View File

@@ -568,6 +568,25 @@ namespace
int v;
};
// Test type designed specifically to test C++20 operator rewriting support
struct my_int :
public boost::equality_comparable2< my_int, int >
{
explicit my_int(int n) : m_n(n) {}
operator int () const
{
return m_n;
}
bool operator== (my_int that)
{
return that.m_n == m_n;
}
int m_n;
};
} // unnamed namespace
@@ -932,5 +951,11 @@ main()
cout << "Performed tests on MyLongInt objects.\n";
my_int my_n = my_int(10);
// Test if C++20 operator rewriting causes infinite recursion (https://github.com/boostorg/utility/issues/65)
BOOST_TEST(my_n == 10);
BOOST_TEST(my_n != 20);
return boost::report_errors();
}