#11570 closed Bugs (fixed)
Boost 1.59.0 breaks lexical_cast to a move-only type (from a string)
Reported by: | Owned by: | Antony Polukhin | |
---|---|---|---|
Milestone: | Boost 1.60.0 | Component: | lexical_cast |
Version: | Boost 1.59.0 | Severity: | Regression |
Keywords: | lexical_cast, move-only, 1.59.0, copy constructor, regression | Cc: |
Description
I think lexical_cast 1.59.0 introduces a regression over 1.58.0 because 1.58.0 allows lexical_cast from string to a move-only type but this now fails to compile.
C++11 example:
#include <boost/lexical_cast.hpp> #include <iostream> #include <string> using boost::lexical_cast; using namespace std; struct my_move_only final { string data; my_move_only() = default; my_move_only(my_move_only &&) = default; my_move_only(const my_move_only &) = delete; }; istream & operator>>(istream &arg_is, my_move_only &arg_mot) { arg_is >> arg_mot.data; return arg_is; } int main() { cerr << "from string gives : " << lexical_cast<my_move_only>( string{ "mr_carbohdrate" } ).data << endl; }
This works against Boost 1.58.0 under both g++ -std=c++11
and clang++ -std=c++11 -stdlib=libc++
but fails against Boost 1.59.0 under both.
The key compile error message appears to be:
boost/lexical_cast.hpp:46:26: error: use of deleted function ‘my_move_only::my_move_only(const my_move_only&)’ return get(result);
(ie, you're trying to copy-construct this move-only type).
It looks to me like this functionality broke with commit bdc355759e.
Is it possible to keep that commit's benefits whilst restoring support for move-only types? Perhaps with some std::move()
magic?
Change History (4)
comment:1 by , 7 years ago
Milestone: | To Be Determined → Boost 1.60.0 |
---|---|
Status: | new → assigned |
comment:2 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Reverted the commit. Attempted to suppress the warnings in this commit.