ISO 10206, paragraph 6.4.9, requires a type-inquiry's type-inquiry-object be either a variable-name (i.e., [imported-interface-identifier '.']variable-identifier) or a parameter-identifier (with a defining point in the closest-containing formal-parameter-list). GPC has a few bugs in enforcing that requirement. As the following test programs demonstrate, GPC will erroneously also accept constant-identifiers, literal numbers, and field-designators as type-inquiry-objects.
{$extended-pascal} program gale9 (output); const c = 2;
var y : type of c; {WRONG} {c is neither a variable-identifier or a parameter-identifier}
begin writeln('FAIL'); end.
{$extended-pascal} program gale10 (output);
var y: type of 3.14; {WRONG} {3.14 isn't an identifier at all let alone being either a variable-identifier or a parameter-identifier}
begin writeln('FAIL'); end.
{$extended-pascal} program gale11 (output);
var x: record f : integer; end; y: record f1: type of x.f; {WRONG} {x.f is a field-designator which isn't a variable-identifier or parameter-identifier} end;
begin writeln('FAIL'); end.
Note: I think the above test programs only show a small sample of what GPC will erroneously accept as a type-inquiry-object. If I'm not completely misunderstanding the compiler source code in this area, it looks like the compiler will accept nearly all, if not all, legal expressions as a type-inquiry-object which is a whole lot more than what my test programs are showing as wrong (as well as, a whole lot more than what ISO requirements allow for a type-inquiry-object).
The compiler I used was the latest version of Mac OS X GPC that Adriaan built and made available for downloading few weeks ago. The specs:
Reading specs from /Developer/Pascal/gpc345u2/lib/gcc/powerpc-apple-darwin8/3.4.5/specs Configured with: ../gcc-3.4.5/configure --enable-languages=pascal,c --enable-threads=posix --target=powerpc-apple-darwin8 --host=powerpc-apple-darwin8 --build=powerpc-apple-darwin8 --prefix=/Developer/Pascal/gpc345u2 Thread model: posix gpc version 20051116, based on gcc-3.4.5
Gale Paeper gpaeper@empirenet.com
Gale Paeper wrote:
ISO 10206, paragraph 6.4.9, requires a type-inquiry's type-inquiry-object be either a variable-name (i.e., [imported-interface-identifier '.']variable-identifier) or a parameter-identifier (with a defining point in the closest-containing formal-parameter-list). GPC has a few bugs in enforcing that requirement. As the following test programs demonstrate, GPC will erroneously also accept constant-identifiers, literal numbers, and field-designators as type-inquiry-objects.
I must admit I fixed this is my own code which I haven't found time to merge (and perhaps regression test). But I can confirm that my version correclty rejects your test programs (the former two always, the last one only in ISO mode, as its result is well-defined, just forbidden by ISO rules).
Note: I think the above test programs only show a small sample of what GPC will erroneously accept as a type-inquiry-object. If I'm not completely misunderstanding the compiler source code in this area, it looks like the compiler will accept nearly all, if not all, legal expressions as a type-inquiry-object which is a whole lot more than what my test programs are showing as wrong (as well as, a whole lot more than what ISO requirements allow for a type-inquiry-object).
You might want to run more extensive tests against my now code. I might have missed some cases you will find.
The following patch may work, but I've just ripped it out of other changes and didn't test it in isolation, so try with care ...
Frank
Frank Heckenbach wrote:
Gale Paeper wrote:
ISO 10206, paragraph 6.4.9, requires a type-inquiry's type-inquiry-object be either a variable-name (i.e., [imported-interface-identifier '.']variable-identifier) or a parameter-identifier (with a defining point in the closest-containing formal-parameter-list). GPC has a few bugs in enforcing that requirement. As the following test programs demonstrate, GPC will erroneously also accept constant-identifiers, literal numbers, and field-designators as type-inquiry-objects.
I must admit I fixed this is my own code which I haven't found time to merge (and perhaps regression test). But I can confirm that my version correclty rejects your test programs (the former two always, the last one only in ISO mode, as its result is well-defined, just forbidden by ISO rules).
Note: I think the above test programs only show a small sample of what GPC will erroneously accept as a type-inquiry-object. If I'm not completely misunderstanding the compiler source code in this area, it looks like the compiler will accept nearly all, if not all, legal expressions as a type-inquiry-object which is a whole lot more than what my test programs are showing as wrong (as well as, a whole lot more than what ISO requirements allow for a type-inquiry-object).
You might want to run more extensive tests against my now code. I might have missed some cases you will find.
The following patch may work, but I've just ripped it out of other changes and didn't test it in isolation, so try with care ...
The patch causes regressions for fjf804.pas and fjf92.pas (error: `type of' applied to a value).
Regards,
Adriaan van Os