Hi,
Thank you for providing GNU Pascal! In the process of migrating from Prospero Pascal to GNU Pascal, it seems I found a bug in the latter. Given the following program:
program stringtest;
type record_with_empty_string = record empty_string : string(127) {VALUE ''}; end; some_records_with_empty_string(length : integer) = array[1..length] of record_with_empty_string; five_records_with_empty_string = some_records_with_empty_string(5);
begin end.
This program compiles. But if you uncomment the initial value of empty_string, GPC complains with "initial value of discriminated schema type is of wrong type". Things like this used to work with Prospero.
Is there a workaround?
Thanks, Bastiaan Veelo.
Bastiaan Veelo wrote:
type record_with_empty_string = record empty_string : string(127) {VALUE ''}; end;
This program compiles. But if you uncomment the initial value of empty_string, GPC complains with "initial value of discriminated schema type is of wrong type". Things like this used to work with Prospero.
Is there a workaround?
Your program builds and runs fine in my environment. What version of gcc and gpc are you using?
I'm running the gpc-20050331 snapshot based on gcc-3.4.3.
Regards,
Markus
Markus Gerwinski wrote:
Bastiaan Veelo wrote:
type record_with_empty_string = record empty_string : string(127) {VALUE ''}; end;
This program compiles. But if you uncomment the initial value of empty_string, GPC complains with "initial value of discriminated schema type is of wrong type". Things like this used to work with Prospero.
Is there a workaround?
Your program builds and runs fine in my environment. What version of gcc and gpc are you using?
I'm running the gpc-20050331 snapshot based on gcc-3.4.3.
No problems here either, with gpc version 20051116, based on gcc-3.4.5 on I386-apple-darwin.
Regards,
Adriaan van Os
Adriaan van Os wrote:
Markus Gerwinski wrote:
Bastiaan Veelo wrote:
type record_with_empty_string = record empty_string : string(127) {VALUE ''}; end;
This program compiles. But if you uncomment the initial value of empty_string, GPC complains with "initial value of discriminated schema type is of wrong type". Things like this used to work with Prospero.
Is there a workaround?
Your program builds and runs fine in my environment. What version of gcc and gpc are you using?
I'm running the gpc-20050331 snapshot based on gcc-3.4.3.
No problems here either, with gpc version 20051116, based on gcc-3.4.5 on I386-apple-darwin.
Regards,
Adriaan van Os
My version is gpc 20051116, based on gcc-3.2.3 (mingw special 20030504-1). Indeed, the program compiles. The problem begins after uncommenting the initial value. Sorry for the confusion :-) For completeness here follows the code that _does not_ compile as is.
program stringtest;
type record_with_empty_string = record empty_string : string(127) VALUE ''; end; some_records_with_empty_string(length : integer) = array[1..length] of record_with_empty_string; five_records_with_empty_string = some_records_with_empty_string(5);
begin end.
On Wed, 19 Jul 2006, Bastiaan Veelo wrote:
Adriaan van Os wrote:
Markus Gerwinski wrote:
Bastiaan Veelo wrote:
type record_with_empty_string = record empty_string : string(127) {VALUE ''}; end;
This program compiles. But if you uncomment the initial value of empty_string, GPC complains with "initial value of discriminated schema type is of wrong type". Things like this used to work with Prospero.
Is there a workaround?
Your program builds and runs fine in my environment. What version of gcc and gpc are you using?
I'm running the gpc-20050331 snapshot based on gcc-3.4.3.
No problems here either, with gpc version 20051116, based on gcc-3.4.5 on I386-apple-darwin.
Regards,
Adriaan van Os
My version is gpc 20051116, based on gcc-3.2.3 (mingw special 20030504-1). Indeed, the program compiles. The problem begins after uncommenting the initial value. Sorry for the confusion :-) For completeness here follows the code that _does not_ compile as is.
program stringtest;
type record_with_empty_string = record empty_string : string(127) VALUE ''; end; some_records_with_empty_string(length : integer) = array[1..length] of record_with_empty_string; five_records_with_empty_string = some_records_with_empty_string(5);
begin end.
tried it - got error message: stringtest.pas:9: error: initial value of discriminated schema type is of wrong type
line 9 is the "five_records ..."
I suspect that without the "VALUE" when the compiler allocates space for a string both the capacity and length fields are initialized, in this case 127 and 0. Frank or Waldek would know for sure.
A nice safe workaround is to initialize your strings with a for-loop.
russ
Bastiaan Veelo wrote:
My version is gpc 20051116, based on gcc-3.2.3 (mingw special 20030504-1). Indeed, the program compiles. The problem begins after uncommenting the initial value. Sorry for the confusion :-) For completeness here follows the code that _does not_ compile as is.
program stringtest;
type record_with_empty_string = record empty_string : string(127) VALUE ''; end; some_records_with_empty_string(length : integer) = array[1..length] of record_with_empty_string; five_records_with_empty_string = some_records_with_empty_string(5);
begin end.
Yes, this is a bug. The following should fix it:
Index: typecheck.c =================================================================== RCS file: /mn/a8/cvsroot/gpc/p/typecheck.c,v retrieving revision 1.12 diff -u -p -r1.12 typecheck.c --- typecheck.c 11 Apr 2006 04:33:16 -0000 1.12 +++ typecheck.c 24 Jul 2006 14:08:02 -0000 @@ -2624,11 +2659,13 @@ build_discriminated_schema_type (tree ty tree t = re_fold (TYPE_LANG_INITIAL (type), TYPE_MAIN_VARIANT (type_template), fix_list, &dummy); CHK_EM (t); +#if 0 if (check_pascal_initializer (type, t)) { error ("initial value of discriminated schema type is of wrong type"); t = error_mark_node; } +#endif TYPE_LANG_INITIAL (type) = t; }
Waldek Hebisch wrote:
Yes, this is a bug. The following should fix it:
Great, thanks. This does not look like the definitive fix though, am I right?
Index: typecheck.c
RCS file: /mn/a8/cvsroot/gpc/p/typecheck.c,v retrieving revision 1.12 diff -u -p -r1.12 typecheck.c --- typecheck.c 11 Apr 2006 04:33:16 -0000 1.12 +++ typecheck.c 24 Jul 2006 14:08:02 -0000 @@ -2624,11 +2659,13 @@ build_discriminated_schema_type (tree ty tree t = re_fold (TYPE_LANG_INITIAL (type), TYPE_MAIN_VARIANT (type_template), fix_list, &dummy); CHK_EM (t); +#if 0 if (check_pascal_initializer (type, t)) { error ("initial value of discriminated schema type is of wrong type"); t = error_mark_node; } +#endif TYPE_LANG_INITIAL (type) = t; }