Title
Can a conversion be done on the left operand of a compound assignment?
Status
nad
Section
12.2.2.3 [over.match.oper]
Submitter
Gennaro Prota

Created on 2003-06-19.00:00:00 last changed 255 months ago

Messages

Date: 2003-10-15.00:00:00

Notes from the October 2003 meeting:

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

Date: 2003-06-19.00:00:00

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.

History
Date User Action Args
2003-11-15 00:00:00adminsetmessages: + msg950
2003-11-15 00:00:00adminsetstatus: open -> nad
2003-06-19 00:00:00admincreate