2014-09-02 16:11 GMT+02:00 Dean Michael Berris
On Wed Sep 03 2014 at 12:00:56 AM Andrzej Krzemienski
wrote: And the above incorrect behaviour is the consequence of a more simple bug in VC++. It allows two user defined conversions in copy initialization:
struct A { A(int &&) {}
};
struct B { operator int() { return 0; } };
int main() { A t = B(); }
This works in VC++, although the code is incorrect.
So it does sound like this is one of those r-value reference implementation bugs in MSVC that I've heard before but couldn't cite. Could it just be that Boost.Optional shouldn't turn on rvalue reference support with MSVC 2010? Will defining just the copy constructor "fix" it? More importantly is there something users of Boost 1.56.0 can do to side-step this particular issue in Boost.Optional?
Would it work for you, if I added an option to configure Boost.Optional at compile time so that it does not have these constructors: optional(T const&); optional(T &&); but instead has these: optional(ConvertibleFromTConstRefWrapper); optional(ConvertibleFromTRefRefWrapper); This would fix your problem on MSVC, remove all double-conversions to optional and provide correct single-conversions by turning MSVC's double-conversions. It wouldn't be enabled by default of course. MSVC users are used to double conversions. I often found myself writing: optionalstd::string os = "c-style string"; Regards, &rzej