https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122259

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yeah, that's just completely wrong. std::pair and std::tuple have
const-qualified operator= for example. And if the object is const but the data
member is mutable, you can assign to it.

The current error might be verbose but is accurate and precise, which is not
true of any of the other suggestions here. The problem is that assignment to a
const std::string cannot find a suitable operator= overload. That doesn't mean
such an overload is impossible in theory, just that there isn't one that
matches the types and value categories of the operands (where the type includes
cv-qualifications). And that's what the current error tells you.

If it was a type that _does_ have a const-qualified operator= but you slightly
messed up some constraints on that operator=, or the right operand is the wrong
type, then just saying something like "cannot assign to const object" would be
wrong and very misleading. Not showing the candidates and why each one failed
to match would make it harder to diagnose the messed up constraints, or the
incorrect type of the right operand.

Reply via email to