This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-10-26


423. Can a conversion be done on the left operand of a compound assignment?

Section: 12.2.2.3  [over.match.oper]     Status: NAD     Submitter: Gennaro Prota     Date: 19 Jun 2003

Is the following well-formed?

  template <typename T>
  class test
  {
  public:
    operator T& (){ return m_i; }
  private:
    T m_i;
  };
  int main()
  {
    test<int*> t2;
    t2 += 1;  // Allowed?
  }

Is it possible that by "assignment operators" (12.2.2.3 [over.match.oper] paragraph 4) only the built-in candidates for operator= (i.e. excluding +=, *=, etc.) were meant? On one hand the plural ("operators") seems to imply that all the assignment operators are considered. OTOH, there has already been a core DR (221) about a missing distinction between "assignment operator" and "compound assignment operators". Is there a similar defect here?

Steve Adamczyk: The standard is ambiguous. However, I think the ARM was fairly clear about "assignment operators" meaning only "=", and I find that Cfront 3.0.1 accepts the test case (with typename changed to class). I don't know whether that's good or bad, but it's at least a precedent. Given the change of Core Issue 221, if we do nothing further conversions are valid on += and therefore this case is valid.

Note that "t2++;" is unquestionably valid, so one could also argue for the status quo (post-221) on the basis of consistency.

Notes from the October 2003 meeting:

We believe the example is well-formed, and no change other than that in issue 221 is needed.