[Issue 671] Weird class reference declaration compiles

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Dec 10 10:43:39 PST 2006


http://d.puremagic.com/issues/show_bug.cgi?id=671


smjg at iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg at iname.com
             Status|RESOLVED                    |REOPENED
           Keywords|                            |accepts-invalid, spec
         Resolution|INVALID                     |




------- Comment #3 from smjg at iname.com  2006-12-10 12:43 -------
operatoroverloading.html

"The assignment operator = can be overloaded if the lvalue is a struct or class
aggregate, and opAssign  is a member function of that aggregate."

The assignment _operator_, that is.  The "t = 20" of "Test t = 20;" is not an
AssignExpression, or indeed any kind of expression, and so it's not using the
assignment operator.  It's a wholly distinct use of the "=" token from a code
structure POV.

If this were to be allowed, it would have to be explicitly specified that
opAssign applies to initializers as well as AssignExpressions.  Even then,
unless as Chris suggests you make it equivalent to

    Test t = (new Test) = 20;

then it makes no sense whatsoever to allow a class (as opposed to struct or
union) variable to be initialized in this way.


-- 



More information about the Digitalmars-d-bugs mailing list