Fix: prevented the binding illegal temporary to optional<const int&>

Older MSVC versions add illegal temporary when you want to assign from const integral value.
This commit is contained in:
Andrzej Krzemienski
2016-02-18 23:18:01 +01:00
parent 1671966380
commit 44d57a1d8b
20 changed files with 161 additions and 109 deletions

View File

@ -39,6 +39,7 @@ import testing ;
[ run optional_test_emplace.cpp ]
[ run optional_test_minimum_requirements.cpp ]
[ run optional_test_msvc_bug_workaround.cpp ]
[ compile-fail optional_test_ref_convert_assign_const_int_prevented.cpp ]
[ compile-fail optional_test_fail1.cpp ]
[ compile-fail optional_test_fail3a.cpp ]
[ compile-fail optional_test_fail3b.cpp ]

View File

@ -163,26 +163,11 @@ void test_rebinding_assignment_semantics()
BOOST_TEST_EQ(val(v), 2);
}
template <typename T>
template <typename T, typename U>
void test_converting_assignment()
{
typename concrete_type_of<T>::type v1(1), v2(2), v3(3);
optional<T&> oA(v1), oB(none);
oA = v2;
BOOST_TEST(oA);
BOOST_TEST(addressof(*oA) == addressof(v2));
oB = v3;
BOOST_TEST(oB);
BOOST_TEST(addressof(*oB) == addressof(v3));
}
template <typename T>
void test_converting_assignment_for_noconst_const()
{
typename concrete_type_of<T>::type v1(1), v2(2), v3(3);
optional<const T&> oA(v1), oB(none);
optional<U&> oA(v1), oB(none);
oA = v2;
BOOST_TEST(oA);
@ -194,4 +179,3 @@ void test_converting_assignment_for_noconst_const()
}
#endif //BOOST_OPTIONAL_TEST_OPTIONAL_REF_ASSIGN_TEST_DEFS_AK_07JAN2015_HPP

View File

@ -23,8 +23,8 @@
int main()
{
test_converting_assignment<const int>();
test_converting_assignment_for_noconst_const<int>();
#ifndef BOOST_OPTIONAL_CONFIG_NO_PROPER_ASSIGN_FROM_CONST_INT
test_converting_assignment<const int, const int>();
#endif
return boost::report_errors();
}

View File

@ -0,0 +1,32 @@
// Copyright (C) 2015 Andrzej Krzemienski.
//
// Use, modification, and distribution is subject to 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)
//
// See http://www.boost.org/lib/optional for documentation.
//
// You are welcome to contact the author at: akrzemi1@gmail.com
#include "boost/optional/optional.hpp"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "boost/core/addressof.hpp"
#include "boost/core/enable_if.hpp"
#include "boost/core/lightweight_test.hpp"
#include "testable_classes.hpp"
#include "optional_ref_assign_test_defs.hpp"
int main()
{
#ifdef BOOST_OPTIONAL_CONFIG_NO_PROPER_ASSIGN_FROM_CONST_INT
test_converting_assignment<const int, const int>();
#else
BOOST_STATIC_ASSERT(false, "EXPECTED TEST COMPILE-TIME FAILURE");
#endif
return boost::report_errors();
}

View File

@ -23,7 +23,8 @@
int main()
{
test_converting_assignment<int>();
test_converting_assignment<int, int>();
test_converting_assignment<int, const int>();
return boost::report_errors();
}

View File

@ -25,9 +25,9 @@
template <typename T>
void test_all_const_cases()
{
test_converting_assignment<T>();
test_converting_assignment<const T>();
test_converting_assignment_for_noconst_const<T>();
test_converting_assignment<T, T>();
test_converting_assignment<const T, const T>();
test_converting_assignment<T, const T>();
}
int main()