Opened 9 years ago
Closed 8 years ago
#9718 closed Bugs (fixed)
boost::container::string assignment operator problem
| Reported by: | Owned by: | Ion Gaztañaga | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | container |
| Version: | Boost 1.53.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
The following code compiles with std::string, but fails to with boost::container::string. The error message is:
stringtest.cpp: In function ‘int main()’:
stringtest.cpp:21:5: error: no match for ‘operator=’ (operand types are ‘Msg’ and ‘const Msg’)
y = x; // ok with std::string, compilation error with boost::container::string
^
stringtest.cpp:21:5: note: candidate is:
stringtest.cpp:7:8: note: Msg& Msg::operator=(Msg&)
struct Msg
^
stringtest.cpp:7:8: note: no known conversion for argument 1 from ‘const Msg’ to ‘Msg&’
...which suggests the assignment operator generated for Msg takes only a Msg reference, not a const one.
Boost 1.53.0 under Cygwin64, compiled using g++ (GCC) 4.8.1.
#include <string>
#include <boost/container/string.hpp>
// using namespace std;
using namespace boost::container;
struct Msg
{
public:
string msg;
};
int main()
{
const string a("hello");
string b;
b = a; // ok
const Msg x;
Msg y;
y = x; // ok with std::string, compilation error with boost::container::string
return 0;
};
Change History (5)
comment:1 by , 9 years ago
| Component: | None → container |
|---|---|
| Owner: | set to |
comment:2 by , 9 years ago
| Component: | container → None |
|---|
comment:3 by , 9 years ago
This is a well-known limitation of Boost.Move:
However, it should be documented in the Container library as a known issue. I'll use this ticket for this.
You'll need to define the assignment operator in the struct to workaround the issue. It's a pain but there is no fix for that.
comment:4 by , 9 years ago
| Component: | None → container |
|---|
Sorry about the component change, it was not intentional. Reverting it.
comment:5 by , 8 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Documentation updated with this known issue in commit:
SHA-1: 9c582e906aa95fa5a6d2383c8d4e4065ebdce160
- Documentation fixes:
- allocator_traits was not properly placed in namespace boost::container
- Fixed some typos
- Added "Known Issues" section with move emulation problems.

Just checked: the code works ok when compiled in the C++11 mode (-std=c++11) but fails in the default mode (no -std specified, i.e. -std=c++03).