mirror of
https://github.com/boostorg/optional.git
synced 2025-07-16 05:42:07 +02:00
fix bug with defaulted move in msvc 12.0
This commit is contained in:
@ -35,7 +35,7 @@ We call it a ['direct] storage. This makes `optional<T>` a trivially-copyable ty
|
|||||||
|
|
||||||
[heading Controlling the size]
|
[heading Controlling the size]
|
||||||
|
|
||||||
For the purpose of the followin analysis, considering memory layouts, we can think of it as:
|
For the purpose of the following analysis, considering memory layouts, we can think of it as:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class optional
|
class optional
|
||||||
|
@ -82,7 +82,7 @@
|
|||||||
the size</a>
|
the size</a>
|
||||||
</h5>
|
</h5>
|
||||||
<p>
|
<p>
|
||||||
For the purpose of the followin analysis, considering memory layouts, we
|
For the purpose of the following analysis, considering memory layouts, we
|
||||||
can think of it as:
|
can think of it as:
|
||||||
</p>
|
</p>
|
||||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">></span>
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">></span>
|
||||||
|
@ -146,7 +146,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||||
<td align="left"><p><small>Last revised: October 28, 2017 at 14:38:14 GMT</small></p></td>
|
<td align="left"><p><small>Last revised: October 30, 2017 at 22:34:46 GMT</small></p></td>
|
||||||
<td align="right"><div class="copyright-footer"></div></td>
|
<td align="right"><div class="copyright-footer"></div></td>
|
||||||
</tr></table>
|
</tr></table>
|
||||||
<hr>
|
<hr>
|
||||||
|
@ -113,4 +113,15 @@
|
|||||||
# define BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
# define BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Detection of correctly implemented defaulted functions
|
||||||
|
|
||||||
|
#ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
|
||||||
|
# define BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_FUNCTIONS
|
||||||
|
#elif BOOST_WORKAROUND(BOOST_MSVC, < 1900)
|
||||||
|
// on MSVC 12.0 move constructor and move assignment are not reconized as special functions
|
||||||
|
// and they cannot be defaulted
|
||||||
|
# define BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_FUNCTIONS
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // header guard
|
#endif // header guard
|
||||||
|
@ -496,4 +496,4 @@ class tc_optional_base : public optional_tag
|
|||||||
|
|
||||||
bool m_initialized ;
|
bool m_initialized ;
|
||||||
T m_storage ;
|
T m_storage ;
|
||||||
} ;
|
} ;
|
||||||
|
@ -954,7 +954,7 @@ class optional
|
|||||||
|
|
||||||
// Creates a deep copy of another optional<T>
|
// Creates a deep copy of another optional<T>
|
||||||
// Can throw if T::T(T const&) does
|
// Can throw if T::T(T const&) does
|
||||||
#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_FUNCTIONS
|
||||||
optional ( optional const& ) = default;
|
optional ( optional const& ) = default;
|
||||||
#else
|
#else
|
||||||
optional ( optional const& rhs ) : base( static_cast<base const&>(rhs) ) {}
|
optional ( optional const& rhs ) : base( static_cast<base const&>(rhs) ) {}
|
||||||
@ -964,7 +964,7 @@ class optional
|
|||||||
// Creates a deep move of another optional<T>
|
// Creates a deep move of another optional<T>
|
||||||
// Can throw if T::T(T&&) does
|
// Can throw if T::T(T&&) does
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_FUNCTIONS
|
||||||
optional ( optional && rhs ) = default;
|
optional ( optional && rhs ) = default;
|
||||||
#else
|
#else
|
||||||
optional ( optional && rhs )
|
optional ( optional && rhs )
|
||||||
@ -1029,7 +1029,7 @@ class optional
|
|||||||
// Assigns from another optional<T> (deep-copies the rhs value)
|
// Assigns from another optional<T> (deep-copies the rhs value)
|
||||||
// Basic Guarantee: If T::T( T const& ) throws, this is left UNINITIALIZED
|
// Basic Guarantee: If T::T( T const& ) throws, this is left UNINITIALIZED
|
||||||
// (NOTE: On BCB, this operator is not actually called and left is left UNMODIFIED in case of a throw)
|
// (NOTE: On BCB, this operator is not actually called and left is left UNMODIFIED in case of a throw)
|
||||||
#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_FUNCTIONS
|
||||||
optional& operator= ( optional const& rhs ) = default;
|
optional& operator= ( optional const& rhs ) = default;
|
||||||
#else
|
#else
|
||||||
optional& operator= ( optional const& rhs )
|
optional& operator= ( optional const& rhs )
|
||||||
@ -1041,7 +1041,7 @@ class optional
|
|||||||
|
|
||||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||||
// Assigns from another optional<T> (deep-moves the rhs value)
|
// Assigns from another optional<T> (deep-moves the rhs value)
|
||||||
#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_FUNCTIONS
|
||||||
optional& operator= ( optional && ) = default;
|
optional& operator= ( optional && ) = default;
|
||||||
#else
|
#else
|
||||||
optional& operator= ( optional && rhs )
|
optional& operator= ( optional && rhs )
|
||||||
|
@ -67,12 +67,14 @@ import testing ;
|
|||||||
[ compile-fail optional_test_fail_none_io_without_io.cpp ]
|
[ compile-fail optional_test_fail_none_io_without_io.cpp ]
|
||||||
[ compile-fail optional_test_fail_convert_assign_of_enums.cpp ]
|
[ compile-fail optional_test_fail_convert_assign_of_enums.cpp ]
|
||||||
[ run optional_test_static_properties.cpp ]
|
[ run optional_test_static_properties.cpp ]
|
||||||
|
[ compile optional_test_maybe_uninitialized_warning.cpp ]
|
||||||
|
[ compile optional_test_deleted_default_ctor.cpp ]
|
||||||
[ run optional_xconfig_NO_PROPER_ASSIGN_FROM_CONST_INT_pass.cpp ]
|
[ run optional_xconfig_NO_PROPER_ASSIGN_FROM_CONST_INT_pass.cpp ]
|
||||||
[ run-fail optional_xconfig_NO_PROPER_ASSIGN_FROM_CONST_INT_fail.cpp ]
|
[ run-fail optional_xconfig_NO_PROPER_ASSIGN_FROM_CONST_INT_fail.cpp ]
|
||||||
[ run optional_xconfig_NO_PROPER_CONVERT_FROM_CONST_INT_pass.cpp ]
|
[ run optional_xconfig_NO_PROPER_CONVERT_FROM_CONST_INT_pass.cpp ]
|
||||||
[ run-fail optional_xconfig_NO_PROPER_CONVERT_FROM_CONST_INT_fail.cpp ]
|
[ run-fail optional_xconfig_NO_PROPER_CONVERT_FROM_CONST_INT_fail.cpp ]
|
||||||
[ run optional_xconfig_NO_LEGAL_CONVERT_FROM_REF_pass.cpp ]
|
[ run optional_xconfig_NO_LEGAL_CONVERT_FROM_REF_pass.cpp ]
|
||||||
[ compile-fail optional_xconfig_NO_LEGAL_CONVERT_FROM_REF_fail.cpp ]
|
[ compile-fail optional_xconfig_NO_LEGAL_CONVERT_FROM_REF_fail.cpp ]
|
||||||
[ compile optional_test_deleted_default_ctor.cpp ]
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include "boost/core/lightweight_test.hpp"
|
#include "boost/core/lightweight_test.hpp"
|
||||||
|
|
||||||
using boost::optional;
|
using boost::optional;
|
||||||
using boost::make_optional;
|
|
||||||
|
|
||||||
template<class Opt>
|
template<class Opt>
|
||||||
void test2( Opt o, Opt buff )
|
void test2( Opt o, Opt buff )
|
||||||
@ -42,10 +41,10 @@ void test2( Opt o, Opt buff )
|
|||||||
template<class T>
|
template<class T>
|
||||||
void test( T v, T w )
|
void test( T v, T w )
|
||||||
{
|
{
|
||||||
test2( make_optional(v), optional<T> ());
|
test2( boost::make_optional(v), optional<T> ());
|
||||||
test2( make_optional(v), make_optional(w));
|
test2( boost::make_optional(v), boost::make_optional(w));
|
||||||
test2( optional<T> () , optional<T> ());
|
test2( optional<T> () , optional<T> ());
|
||||||
test2( optional<T> () , make_optional(w));
|
test2( optional<T> () , boost::make_optional(w));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
32
test/optional_test_maybe_uninitialized_warning.cpp
Normal file
32
test/optional_test_maybe_uninitialized_warning.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright (C) 2017 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
|
||||||
|
|
||||||
|
boost::optional<int> getitem();
|
||||||
|
|
||||||
|
int main(int argc, const char *[])
|
||||||
|
{
|
||||||
|
boost::optional<int> a = getitem();
|
||||||
|
boost::optional<int> b;
|
||||||
|
|
||||||
|
if (argc > 0)
|
||||||
|
b = argc;
|
||||||
|
|
||||||
|
if (a != b)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -137,4 +137,4 @@ int main()
|
|||||||
test_trivial_copyability();
|
test_trivial_copyability();
|
||||||
#endif
|
#endif
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user