使用msvc2017编译器并升级1.65.1,下面的代码无法编译。
#include <boost/optional.hpp>
boost::optional<double>
foo()
{
return boost::optional<double>(4.0);
}
int
main(void)
{
boost::optional<double> result;
result = foo();
}
生成的错误是:
C:/boost/optional/optional.hpp(954): error C2248: 'boost::optional_detail::optional_base<T>::optional_base': cannot access protected member declared in class 'boost::optional_detail::optional_base<T>'
with
[
T=double
]
C:/boost/optional/optional.hpp(157): note: see declaration of 'boost::optional_detail::optional_base<T>::optional_base'
with
[
T=double
]
C:/boost/optional/optional.hpp(771): note: see declaration of 'boost::optional_detail::optional_base<T>'
with
[
T=double
]
C:/boost/optional/optional.hpp(954): note: while checking that elided copy-constructor 'boost::optional_detail::optional_base<T>::optional_base(const boost::optional_detail::optional_base<T> &)' is callable
with
[
T=double
]
C:/boost/optional/optional.hpp(157): note: see declaration of 'boost::optional_detail::optional_base<T>::optional_base'
with
[
T=double
]
C:/boost/optional/optional.hpp(954): note: when converting from 'boost::optional_detail::optional_base<T>' to 'boost::optional_detail::optional_base<T> &&'
with
[
T=double
]
C:/boost/optional/optional.hpp(953): note: while compiling class template member function 'boost::optional<double> &boost::optional<double>::operator =(boost::optional<double> &&) noexcept'
main.cpp(13): note: see reference to function template instantiation 'boost::optional<double> &boost::optional<double>::operator =(boost::optional<double> &&) noexcept' being compiled
main.cpp(5): note: see reference to class template instantiation 'boost::optional<double>' being compiled
其他编译器不会出现此问题(我测试了clang和gcc)。所以这对我来说似乎是一个Microsoft编译器错误?