Wood David wrote:
Hi (Frank),
I'm just trying gpc20030209 with gcc 3.2.1 and I've got a new error since the 2.1 build:
"reference parameter passing of variant record selector"
I don't understand what's illegal
6.7.3.3:
: An actual variable parameter shall not denote a field that is the selector : of a variantÂÂpart.
I think the reason is for cases such as the following:
program Foo (Output);
procedure Foo (var a, b: Boolean); begin WriteLn (a); b := True; WriteLn (a) end;
type t = record case a: Boolean of False: (b: Boolean); True: () end;
var v: t;
begin v.b := False; v.a := False; Foo (v.a, v.b) end.
Here, the first `WriteLn' would be valid, the second one invalid. Furthermore, the procedure doesn't know about the variant record at all, so it can't easily check it (in an implementation that implements variant checking which GPC doesn't do (yet)). That would mean that *every* reference parameter would have to be checked, in a way that the called routine doesn't even know about. This would be a big overhead (maybe using callbacks for checking etc.) and might be a performance killer.
So it was decided (rightfully IMHO) to not allow such constructs in the first place.
and the syntax of this error message is hard to understand. I think it means "variant record selector cannot be passed by reference"
I'll change it.
The workaround is to use a temporary variable for the enumerated type in the procedure call, and then copy it to the selector afterwards.
This seems to be just a way of avoiding a previously legal construct in the first place.
It was never "legal". GPC just didn't detect it before (like it still misses many other errors).
Frank