Operator overloading of variant records in delphi mode
Original Reporter info from Mantis: CWBudde
-
Reporter name: Christian Budde
Original Reporter info from Mantis: CWBudde
- Reporter name: Christian Budde
Description:
For variant records such as
type
TTestRecord = record
case Boolean of
False: (Value: Single);
True: (AsInteger: Integer);
end;
it's not possible to overload operators in delphi mode.
Due to Delphi compatibility (?!?) the case expression needs to be last in the record definition resulting in something like:
type
TTestRecord = record
public
class operator Add(const Lhs, Rhs: TTestRecord): TTestRecord;
class operator Subtract(const Lhs, Rhs: TTestRecord): TTestRecord;
case Boolean of
False: (Value: Single);
True: (AsInteger: Integer);
end;
While there is no problem with this construct so far, the compiler complains on the line of the implementation of Add(..) or Subtract(..) with this message:
'Error function header doesn't match the previous declaration "operator +(const TTestRecord, const TTestRecord): &LtPos;record type>;"
I guess this because of the result '&LtPos;record type>' not being identified as TTestRecord, as it may not be completed during parsing the record.
If another operator such as 'Equal' is overloaded (with a Boolean as result), there's no problem.
Also if straight arrays are used (not variant), there are also no problems with this expression.
Steps to reproduce:
see attached program...
if 'SIMPLE' is defined, everything compiles fine. Note also, that there is no problem with the operator overloading of Equal(..)
Mantis conversion info:
- Mantis ID: 21044
- OS: Windows
- OS Build: 7
- Build: [2012/01/05], x86_64
- Platform: Apple MacBook
- Version: 2.7.1
- Fixed in version: 3.0.0
- Fixed in revision: 20161 (#d752ce2c)
- Monitored by: » CWBudde (Christian Budde)