boost::variant & c++11
Hi - I seem to have run into a regression with boost::variant from 1.48 to 1.53. With C++11 enabled, using g++, the following code seems to confuse variant's constructor selection machinery: if you look at the line after #ifndef WAR, the implicit conversion isn't happening, and so boost::variant attempts to convert construct from extract<my_variant> to A or B. It should instead copy construct from the output of extract<my_variant>'s implicit conversion to my_variant. If I force an explicit conversion, this problem doesn't occur. If I don't enable c++11, this problem doesn't occur. With Boost 1.48, this problem doesn't occur. Any advice from the list as to why this behavior changed? Thanks, bryan #include <boost/variant.hpp> //A simplified wrapper template<typename T> struct wrap { T t; wrap(T& _t) : t(_t) {} operator T() const { return t; } T force() const { return t; } }; struct A{}; struct B{}; typedef boost::variant<A, B> my_variant; int main() { A a; my_variant x(a); #ifndef WAR my_variant y = wrap<my_variant>(x); #else my_variant y = wrap<my_variant>(x).force(); #endif } And the error: /home/bcatanzaro/boost_1_53_0/boost/variant/variant.hpp:1574:9: error: no matching function for call to ‘boost::variant<A, B>::initializer::initialize(void*, std::remove_reference<wrap<boost::variant<A, B> >&>::type)’
#include <boost/variant.hpp> //A simplified wrapper template<typename T> struct wrap { T t; wrap(T& _t) : t(_t) {} operator T() const { return t; } T force() const { return t; } };
struct A{}; struct B{};
typedef boost::variant<A, B> my_variant;
int main() { A a; my_variant x(a); #ifndef WAR my_variant y = wrap<my_variant>(x); #else my_variant y = wrap<my_variant>(x).force(); #endif }
And the error:
/home/bcatanzaro/boost_1_53_0/boost/variant/variant.hpp:1574:9: error: no matching function for call to ‘boost::variant<A, B>::initializer::initialize(void*, std::remove_reference<wrap<boost::variant<A, B> >&>::type)’
FWIW, your case can be reproduced with even more trivial code: #include <boost/variant.hpp> typedef boost::variant<int> my_variant; struct convertible { operator my_variant() const { return my_variant(); } }; int main() { convertible x; my_variant y = x; }
2013/5/8 Igor R <boost.lists@gmail.com>:
#include <boost/variant.hpp> //A simplified wrapper template<typename T> struct wrap { T t; wrap(T& _t) : t(_t) {} operator T() const { return t; } T force() const { return t; } };
struct A{}; struct B{};
typedef boost::variant<A, B> my_variant;
int main() { A a; my_variant x(a); #ifndef WAR my_variant y = wrap<my_variant>(x); #else my_variant y = wrap<my_variant>(x).force(); #endif }
And the error:
/home/bcatanzaro/boost_1_53_0/boost/variant/variant.hpp:1574:9: error: no matching function for call to ‘boost::variant<A, B>::initializer::initialize(void*, std::remove_reference<wrap<boost::variant<A, B> >&>::type)’
FWIW, your case can be reproduced with even more trivial code:
#include <boost/variant.hpp>
typedef boost::variant<int> my_variant; struct convertible { operator my_variant() const { return my_variant(); } };
int main() { convertible x; my_variant y = x; }
I'll take care of that issue, but not 100% sure that there will be enough time to push fix to 1.54. There is a ticket for that issue: https://svn.boost.org/trac/boost/ticket/8555 . -- Best regards, Antony Polukhin
2013/5/10 Antony Polukhin <antoshkka@gmail.com>:
2013/5/8 Igor R <boost.lists@gmail.com>:
#include <boost/variant.hpp> //A simplified wrapper template<typename T> struct wrap { T t; wrap(T& _t) : t(_t) {} operator T() const { return t; } T force() const { return t; } };
struct A{}; struct B{};
typedef boost::variant<A, B> my_variant;
int main() { A a; my_variant x(a); #ifndef WAR my_variant y = wrap<my_variant>(x); #else my_variant y = wrap<my_variant>(x).force(); #endif }
Reproduced that error on 1.48.0 using MSVC.
FWIW, your case can be reproduced with even more trivial code:
#include <boost/variant.hpp>
typedef boost::variant<int> my_variant; struct convertible { operator my_variant() const { return my_variant(); } };
int main() { convertible x; my_variant y = x; }
Reproduced that error on 1.48.0 using MSVC. Looks like this problem is not affected by latest changes in Boost. Have you changed the compiler during migration to Boost 1.53? Have been some code changes made during migration? Do you compile with same options before and after migration? -- Best regards, Antony Polukhin
participants (3)
-
Antony Polukhin
-
Bryan Catanzaro
-
Igor R